I have the following in my playbook, and when it writes the contents it writes in this format:
ServerA:
sudoers
ServerB:
sudoers
ServerA:
other_users
ServerB:
other_users.
I would like the following format if possible:
ServerA
sudoers
ServerA
other_users
ServerB
sudoers
ServerB
other_users
`
- name: Write users
lineinfile:
dest: “/tmp/users.txt”
line: “HOST: {{ansible_nodename}}\n{{item}}\n\n”
insertafter: EOF
create: yes
state: present
delegate_to: localhost
with_items:
- “{{sudoers.stdout_lines|to_nice_json}}”
- “{{other_users.stdout_lines|to_nice_json}}”
notify:
- email
- cleanup
`
I have a way to do this, but am looking for improvements.
If I change the “forks =” setting in the ansible.cfg file, then this works exactly the way I want it to. I don’t mind creating a custom ansible.cfg file (ie ansible_1fork.cfg), but I don’t yet see a way to call the playbook with the custom.cfg (I will be calling it via cron).
I tried “serial: 1”, but I get too many emails… I want just the one email.
Any ideas?
I have it… kind of ugly, but it works. ANSIBLE_CONFIG is an environment variable I can work with. I have to export it to get it to work. I set it to what I need for this one playbook, and then set it back to the default after it is complete.
1 2 1 1-12/3 * export ANSIBLE_CONFIG=“/etc/ansible/ansible_1fork.cfg”; ansible-playbook /playbooks/fetch_server_admins/fetch_server_admins.yml -e “host=myservers”; export ANSIBLE_CONFIG=“/etc/ansible/ansible.cfg”