(This might appear twice, sorry).

(Ansible 2.2 - Mac OS 12.1) 

I'm having trouble with a template I'm trying to create. So, I cut 
it down to a bare minimum. 

Consider the following: 

jon.yml 
--------------------------------- 
--- 
- name: big test 
  hosts: all 
  gather_facts: no 
  tasks: 
    - debug: var=inventory_hostname 
    - name: test for jon 
      template: src=templates/jon.j2 dest=jon.conf 
----------------------------------- 
jon.inv 
----------------------------------- 
[datacenter] 
host1.example.com 
host2.example.com 

[ntpservers-datacenter] 
host1.example.com 
------------------------------------ 

templates/jon.j2 
------------------------------------ 
{% for backend in groups['ntpservers-datacenter'] %} 
    server {{ 'ansible_hostname' }} {{ backend }} 
{% endfor %} 
------------------------------------ 

When running 

ansible-playbook jon.yml -i jon.inv 

I was expecting jon.conf to end up with something like 

server host1.example.com host1.example.com 
server host1.example.com host2.example.com 
server host2.example.com host1.example.com 
server host2.example.com host2.example.com 


Instead, I get the correct debug output, and then 

fatal: [host1.example.com]: UNREACHABLE! => {"changed": false, "msg": 
"Failed to connect to the host via ssh: ssh: Could not resolve hostname 
host1.example.com: nodename nor servname provided, or not known\r\n", 
"unreachable": true} 
fatal: [host2.example.com]: UNREACHABLE! => {"changed": false, "msg": 
"Failed to connect to the host via ssh: ssh: Could not resolve hostname 
host2.example.com: nodename nor servname provided, or not known\r\n", 
"unreachable": true} 

This surprised me because I'm not trying to actually connect to 
anything. I'm just trying to create jon.conf which doesn't get created
in this case.

What am I doing wrong? Any other advice for debugging template problems 
like this? 

What I'm really trying to do is to go through my inventory and see if 
each host is in a specific group. If it is, I want to a specific set 
of configuration commands to a file. If not, I want to write a different 
specific set of configuration commands to the file. This is to create 
one ntp.conf file for hosts that are ntp servers, and another for hosts 
that are ntp clients. 

Any suggestions would be appreciated. 

Cordially 
Jon Forrest 
[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/67a6ccf7-43c6-4a31-87c8-0ba7ce91388e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to