Hi Al,
I get the following error below whenever I try to run dynamic playbook for cisco.ios.ios_l2_interfaces module on ansible.
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: in "<unicode string>", line 3, column 7
fatal: [switch11]: FAILED! => {"changed": false}
Here is my playbook below:
---
- name: Configure Layer2 on Cisco Routers using Jinja2 Templates
hosts: cisco_switches #==> all hosts inventory
gather_facts: no
tasks:
- name: Generate L2 configuration from Jinja2 template
template: # Ansible template directive
src: templates/l2.j2 # ==> ref template
dest: /tmp/l2_vlan.yaml
- name: Debug the rendered configuration
debug:
msg: "{{ lookup('file', '/tmp/l2_vlan.yaml') }}"
- name: Load Generated Configuration
set_fact:
l2_config: "{{ lookup('file', '/tmp/l2_vlan.yaml') | ansible.builtin.from_yaml }}"
- name: Apply L2 configuration to the switch
cisco.ios.ios_l2_interfaces:
config: "{{ l2_config }}"
state: merged
register: config_result
- name: show config result
debug:
msg: "{{ config_result }}"
- name: save l2 config output
ios_command:
commands:
- show int trunk
- show vlan bri
- show ip int bri
register: l2_output
- name: show l2 output via debug
debug:
var: l2_output.stdout_lines
Here is my jinja2 template
{% for value in vlan_stuff %}
- name: {{ value.name }}
mode: "{{ value.mode }}"
access:
vlan: "{{ value.vlan }}"
{% endfor %}
Here is my switch
vlan_stuff:
- name: GigabitEthernet0/3
mode: access
access:
vlan: 10 - name: GigabitEthernet0/2
mode: access
access:
vlan: 11