following situation. I have 3 plays in total. In the first play I filter a routername and register it in a variable, let's call this variable pe. pe is used in the second play as a host, like this
- hosts: "{{ hostvars['firsthost']['pe']['stdout'] }}"
In my second play I do some actions and afterwards I prepare some output which I store in another variables. Like this:
- name: verify PE ping
set_fact:
temp_pe_output: '{{ "WAN interface vrf" "{{ vrf }}" "on PE is NOT reachable" if "{{ ping_output_pe.stdout }}" is search("0/5") else "WAN interface vrf " "{{ vrf }}" " on PE is reachable"}
Now in my third play I want to use these variables from the second play. After several attempts I end with this error after trying to run this task:
- name: Find the connected PE
ansible.builtin.shell: grep "description DL" {{ varnet }}/{{ router }}.cfg | awk '{print tolower($5)}'
register: per
- name: Prepare Article
set_fact:
article: |
{{ hostvars[{{ per.stdout }}]['temp_cpe_output'] }}
Test
TASK [Prepare Article] *****************************************************************************************************************************************************************************
fatal: [thirdhost]: FAILED! => {"msg": "template error while templating string: expected token ':', got '}'. String: \"{{ hostvars[{{ per.stdout }}]['temp_cpe_output'] }}\"\n\"Test\"\n"}
per.stdout contains the name of the 2nd host. Is there a hole in my logic and what does that error mean?