Hi, I am trying to use Ansible to reference a file to populate variables
onto my mail playbook and having issues. Inline and using Jinja templates
work but not with this specific configuration.
Here's my main loop3.yml file
# Add Servers
- name: Add Server Objects from a loop
hosts: dev_servers
gather_facts: false
vars_files:
- server_vars2.yml
tasks:
- name: Create Server "{{ item.svrname }}"
delegate_to: localhost
server:
name: "{{ item.svrname }}"
ipaddress: "{{ item.svrip }}"
state: present
comment: Apache Server "{{ item.svrname }}" with IP "{{
item.svrip }}"
with_items: "{ { serverlist } }"
Here's the file: server_vars2.yml
---
serverlist:
- { svrname: Mike, svrip: 1.2.3.4 }
- { svrname: Sharon, svrip: 5.6.7.8 }
- { svrname: Kimmie, svrip: 9.7.8.9 }
The error that I am getting is:
PLAY [Add Server Objects from a loop]
*******************************************************************************************************************************************************************************************************
TASK [Create Server "{{ item.svrname }}"]
***************************************************************************************************************************************************************************************************
fatal: [dev_servers]: FAILED! => {"msg": "The task includes an option with
an undefined variable. The error was:
'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute
'svrname'\n\nThe error appears to have been in
'/home/xxxxx/xxxx-ansible-modules/loop3.yml': line 14, column 9, but
may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe
offending line appears to be:\n\n tasks:\n - name: Create Server \"{{
item.svrname }}\"\n ^ here\nWe could be wrong, but this one looks
like it might be an issue with\nmissing quotes. Always quote template
expression brackets when they\nstart a value. For instance:\n\n
with_items:\n - {{ foo }}\n\nShould be written as:\n\n
with_items:\n - \"{{ foo }}\"\n"}
My understanding is that:
1. I am using the var_files to reference the file server_vars.yml
2. I am looping through the dict list in server_vars2.yml using the
with_items {serverlist}
I see some conflicting info about referencing the variables, some suggest
using item.variablename, others suggest using item.item.variablename. I
tried both and they don't work. Any help would be appreciated! - Jay.
--
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/b47f54b3-486d-4702-ba00-62e98cc36a52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.