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
What sticks out as a sore thumb is the last line, there should not be any space between {{ and }}.
And for the record, you should be consistent with your indentation, YAML only support spaces and you should the same amount of spaces for the indentation.
After the vars_files: you use 2 spaces, but after the tasks: you use 4 spaces.
This does not create a problem for you in this example, but for the future it is a bad idea to not keep the indentation uniform.
Kai,
Thanks. Noted on the indentation. I was able to resolve this issue by using a different editor and manually updating all the quotes. It was able to execute successfully after that. - J.