Hello,
I am trying to generate hostlist.conf on munin machine based on inventory variables, i have something like this in template
hostlist.j2
{% for items in groups['all'] %}
[{{ hostvars[items]['inventory_hostname_short'] }}.{{ hostvars[items]['role_long'] }}.{{ domain }}]
address ssh://user@{{ hostvars[items]['ansible_default_ipv4']['address'] }}:{{ hostvars[items]['ansible_ssh_port']|default(22) }} --spooldir /var/lib/munin-async/ --spoolfetch
use_node_name yes
load.load.warning :50
ntp_offset.offset.warning -1000:1000
ntp_offset.offset.critical -10000:10000
{% endfor %}
and test.yml which in turn calls hostlist.j2 template:
---
- hosts: all
remote_user: user
sudo: True
name: Smth
tasks:
- name: Generate munin-hostlist.conf
template:
src=modules/helpers/hostlist.j2
dest=/tmp/hostlist_test
delegate_to: foo.acme.com
I am running all this on all hosts (not limited to any specific host) with ansible-playbook test.yml -f 200.
During the execution i get a bunch of seemingly random errors on almost all the hosts (some report OK, some changed but most of them report errors as below):
fatal: [host1.acme.com -> foo.acme.com] => ssh connection closed waiting for sudo or su password prompt
failed: [host2.acme.com -> foo.acme.com] => {"failed": true, "parsed": false}
fatal: [host3.acme.com -> foo.acme.com] => failed to transfer file to /home/user/.ansible/tmp/ansible-tmp-1411730299.82-163702781686018/copy:
mux_client_request_session: session request failed: Session open refused by peer
ssh_exchange_identification: Connection closed by remote host
Couldn't read packet: Connection reset by peer
ok: [host4.acme.com -> foo.acme.com]
However, despite the errors, the resulting file is generated as it should be.
Please note that these servers are accessible and i can run other playbooks just fine on all my hosts.
My question is: is this normal behaviour or am i doing something wrong and is there a way to get this to execute normally without the errors? Do i have to run this on all hosts (because i need host vars and host facts) even though i need the resulting file on one machine?
Keep up the excellent work with Ansible! Thank you in advance!!!
Best regards,