Why do I have to split up this set_fact into multiple? or am I doing something incorrect?

17 views
Skip to first unread message

Marcos Georgopoulos

unread,
May 9, 2018, 1:56:16 AM5/9/18
to Ansible Project


Hi can someone please explain why the following two seperate 'set_fact's work.  


  - name : combine network and wildcard 

    set_fact:

       net_mask: "{{ '{{network}}/{{wildcard}}' }}"

    when: ansible_network_os == 'asa'


  

  - name : determine netmask from wildcard

    set_fact:

        mynetmask: "{{ net_mask  |ipaddr('netmask') }}"

    when: ansible_network_os == 'asa'


 

But this 'combined' effort doesn't work



  - name : determine netmask from network and wildcard

    set_fact:

        mynetmask : "{{ '{{network}}/{{wildcard}}'  |ipaddr('netmask') }}"

    when: ansible_network_os == 'asa'



I'm trying to understand the limitations of set_facts. 


Cheers.

Kai Stian Olstad

unread,
May 9, 2018, 6:39:42 AM5/9/18
to ansible...@googlegroups.com
On 09.05.2018 07:56, Marcos Georgopoulos wrote:
> Hi can someone please explain why the following two seperate
> 'set_fact's
> work.
>
> - name : combine network and wildcard
> set_fact:
> net_mask: "{{ '{{network}}/{{wildcard}}' }}"
> when: ansible_network_os == 'asa'

You can't use {{ }} inside {{ }}
So correct syntax is

- name : combine network and wildcard
set_fact:
net_mask: '{{network}}/{{wildcard}}'
when: ansible_network_os == 'asa'


> - name : determine netmask from wildcard
> set_fact:
> mynetmask: "{{ net_mask |ipaddr('netmask') }}"
> when: ansible_network_os == 'asa'
>
>
> But this 'combined' effort doesn't work
>
> - name : determine netmask from network and wildcard
> set_fact:
> mynetmask : "{{ '{{network}}/{{wildcard}}' |ipaddr('netmask')
> }}"
> when: ansible_network_os == 'asa'

- name : determine netmask from network and wildcard
set_fact:
mynetmask : "{{ (network ~ '/' ~ wildcard) |ipaddr('netmask')
}}"
when: ansible_network_os == 'asa'


> I'm trying to understand the limitations of set_facts.

There is no limitation, you just need to use the correct jinja2 syntax.

--
Kai Stian Olstad

Marcos Georgopoulos

unread,
May 10, 2018, 3:09:04 AM5/10/18
to Ansible Project
Thank you very much. It looks like I have some reading to do :)

Cheers

Reply all
Reply to author
Forward
0 new messages