I've got a role I'm using for testing, but I seem to be stumbling at the
first hurdle.
My embryonic playbook looks like this:
---
- hosts: localhost
sudo: yes
vars:
shinken_hosts:
- {name: hostname1, address: 1.2.3.4, check_command: check-host-alive }
- {name: hostname2, address: 5.6.7.8, check_command: check-ssh,
ssh_port: 2242, contacts: 'jerry,other' }
roles:
- role: shinkenconfig
The shinkenconfig role has a defaults/main.yml:
---
ssh_port: "22"
contacts: "jerry"
check_command: "check-host-alive"
..plus a template to chuck everything into for the actual config:
{% for host in shinken_hosts %}
define host{
use generic-host
host_name {{ host.name }}
address {{ host.address }}
alias {{ host.name }}
check_command {{ host.check_command }}
_SSHPORT {{ host.ssh_port }}
contacts {{ host.contacts }}
}
{% endfor %}
The main task just grabs everything using the template module to write the
file out.
If all the vars are populated in the main playbook, everything works fine,
but I want some default values to populate via the role if they're not
defined. If I take some of the vars out of the playbook (as in the first
"hostname1" line above), ansible-playbook throws this:
fatal: [127.0.0.1] => {'msg': "AnsibleUndefinedVariable: One or more
undefined variables: 'dict object' has no attribute 'ssh_port'", 'failed':
True}
fatal: [127.0.0.1] => {'msg': "AnsibleUndefinedVariable: One or more
undefined variables: 'dict object' has no attribute 'ssh_port'", 'failed':
True}
FATAL: all hosts have already failed -- aborting
...but shouldn't it be pulling the vars out of defaults/main.yml, if
they're not in the playbook? I'm willing to believe I got the YAML syntax
wrong in the defaults/main.yml - if so, would someone be able to correct it?
Any ideas?
Thanks
--
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/b1a0c840-d188-402a-94b9-777a12696278%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.