Below is my ansible role > defaults/main.yaml
 $cat roles/logrotate/defaults/main.yml logrotate_conf_dir: "/etc/logrotate.d/" logrotate_scripts: - name: test log_dir: '/var/log/test' log_extension: 'log' options: - rotate 7 - weekly - size 10M - missingok - compress - create 0644 test test scripts: postrotate: "echo test >> /var/log/test.log" and my task/main.yaml has
 $ cat roles/logrotate/tasks/main.yaml # tasks file for nginx - name: Setup logrotate scripts template: src: logrotate.d.j2 dest: "{{ logrotate_conf_dir }}{{ item.name }}" with_items: "{{ logrotate_scripts }}" when: logrotate_scripts is defined Getting the below error while running this simple playbook:
TASK [logrotate : Setup logrotate scripts] ******************************************************************************************************* An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems' failed: [10.20.5.72] (item={'name': 'test', 'log_dir': '/var/log/test', 'log_extension': 'log', 'options': ['rotate 7', 'weekly', 'size 10M', 'missingok', 'compress', 'create 0644 test test'], 'scripts': {'postrotate': 'echo test >> /var/log/test.log'}}) => {"ansible_loop_var": "item", "changed": false, "item": {"log_dir": "/var/log/test", "log_extension": "log", "name": "test", "options": ["rotate 7", "weekly", "size 10M", "missingok", "compress", "create 0644 test test"], "scripts": {"postrotate": "echo test >> /var/log/test.log"}}, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'iteritems'"}
logrotate.d.j2