How to create a task dict from a templated variable
631 views
Skip to first unread message
Gianni Stubbe
unread,
Apr 13, 2021, 10:52:06 AM4/13/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
Hello,
I have a variable file that defines the config state of my network hardware. As I would need to create lots of if and loops in loops I would like to be able to template the modules so that the amount of sessions I open to the device stays low.
I currently have this but this does not work as I get the error: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "Failure when processing no_log parameters. Module invocation will be hidden. dictionary requested, could not parse JSON or key=value"}
- name: L2 - Config Arista block: - set_fact: physical_interface_config: | {% for L2_phys in L2.physical %} - name: {{ L2_phys.name }} {% if L2_phys.description is defined and L2_phys.description != "" %} description: "{{ L2_phys.description }}" {% endif %} {% if L2_phys.mtu is defined %} mtu: {{ L2_phys.mtu }} {% endif %} {% if L2_phys.autoneg is defined and L2_phys.autoneg %} duplex: auto {% endif %} {% if L2_phys.link_speed is defined %} speed: {{ L2_phys.link_speed }} {% endif %} {% if L2_phys.vid is not defined %} mode: layer3 {% else %} mode: layer2 {% endif %} {% endfor %} L2_config: | {% for L2_phys in L2.physical %} - name: {{ L2_phys.name }} {%- if L2_phys.vid is defined %} {%- if L2_phys.vid.untagged is defined %} untagged: vlan: {{ L2_phys.vid.untagged }} {%- endif %} {%- if L2_phys.vid.tagged is defined %} trunk: vlan: {{ L2_phys.vid.tagged }} {%- if L2_phys.vid.pvid is defined %} native_vlan: {{ L2_phys.vid.pvid }} {%- endif %} {%- endif %} {%- endif %} {%- endfor %}
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
On 4/13/21 4:52 PM, Gianni Stubbe wrote:
>
> Hello,
>
> I have a variable file that defines the config state of my network hardware. As I would need to create lots of if and
> loops in loops I would like to be able to template the modules so that the amount of sessions I open to the device stays
> low.
>
> I currently have this but this does not work as I get the error:
> FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "Failure
> when processing no_log parameters. Module invocation will be hidden. dictionary requested, could not parse JSON or
> key=value"}
>
The module expects a list in the config parameter, but you are passing a string with contains (hopefully valid) YAML.