Hi all,

I am new to ansible.
Why is my playbook not working?
And how can I solve it?

My playbook:

---
- name: print out ip adressess
  hosts: db_servers
  gather_facts: True
  vars:
    - nic: "enp0s8"
    - full_line: ""

  tasks:
  - debug: var=ansible_{{ nic }}.ipv4.address

  - set_fact: full_line="{{ full_line }} {{ 
hostvars[item].ansible_enp0s8.ipv4.address }}"
    loop: "{{ groups['db_servers'] }}"

  - debug:
      msg: "{{ full_line }}"

  - set_fact: full_line="{{ full_line }} {{ hostvars[item].ansible_{{ nic 
}}.ipv4.address }}"
    loop: "{{ groups['db_servers'] }}"

  - debug:
      msg: "{{ full_line }}"


The output:


PLAY [print out ip adressess] 
**********************************************************************************************
TASK [Gathering Facts] 
*****************************************************************************************************
ok: [dbs11]
ok: [dbs10]
TASK [debug] 
***************************************************************************************************************
ok: [dbs10] => {
    "ansible_enp0s8.ipv4.address": "192.168.152.174"
}
ok: [dbs11] => {
    "ansible_enp0s8.ipv4.address": "192.168.152.181"
}
TASK [set_fact] 
************************************************************************************************************
ok: [dbs10] => (item=dbs10)
ok: [dbs10] => (item=dbs11)
ok: [dbs11] => (item=dbs10)
ok: [dbs11] => (item=dbs11)
TASK [debug] 
***************************************************************************************************************
ok: [dbs10] => {
    "msg": " 192.168.152.174 192.168.152.181"
}
ok: [dbs11] => {
    "msg": " 192.168.152.174 192.168.152.181"
}
TASK [set_fact] 
************************************************************************************************************
fatal: [dbs10]: FAILED! => {"msg": "template error while templating string: 
expected token 'end of print statement', got '{'. String: {{ full_line }} 
{{ hostvars[item].ansible_{{ nic }}.ipv4.address }}"}
fatal: [dbs11]: FAILED! => {"msg": "template error while templating string: 
expected token 'end of print statement', got '{'. String: {{ full_line }} 
{{ hostvars[item].ansible_{{ nic }}.ipv4.address }}"}
PLAY RECAP 
*****************************************************************************************************************
dbs10                      : ok=4    changed=0    unreachable=0    
failed=1    skipped=0    rescued=0    ignored=0
dbs11                      : ok=4    changed=0    unreachable=0    
failed=1    skipped=0    rescued=0    ignored=0


With regards,

Herman


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b41e4394-d68b-4a7f-9199-1fb1b297dc36%40googlegroups.com.

Reply via email to