(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
nob...@gmail.com