Trying to write an ansible-playbook that will query a switchport description, register it as a variable and then reapply it plus add text and the date/time.
- name: Verifying Interface Description
ios_command:
provider:
username: "{{ username }}"
password: "{{ password }}"
commands:
- command: "show derived-config interface GigabitEthernet{{ switch_interface }} | include description"
register: interface_description
- debug:
msg:
"{{ interface_description }} Updated {{ ansible_date_time.date }}"
But the value I get when I run the playbook is:
TASK [debug] *************************************************************************************************************************************************************************************************
ok: [NG-1-DA] => {
"msg": "{'failed': False, u'changed': False, u'stdout_lines': [[u'description DataJack123']], u'stdout': [u'description DataJack123']} Updated 2024-04-23"
}
The text and the date/time work, but for some reason the reference to the interface description fails and I can't seem to figure out why.
I'm not sure I understand the error message associated with the interface_description variable and why the reference is failing.
I found there answer in this post - Ansible Print IOS output on string match
I had to use the {{ interface_description.stdout_lines | join(" ") }} to turn it back into a string, as it was previously a list value.