2020-10-28 20:39:20 +00:00
|
|
|
---
|
2020-10-21 17:45:34 +00:00
|
|
|
#### Simple examples
|
2022-12-28 07:07:35 +00:00
|
|
|
- name: Set fact
|
|
|
|
ansible.builtin.set_fact:
|
2020-10-21 17:45:34 +00:00
|
|
|
a:
|
|
|
|
b:
|
|
|
|
c:
|
|
|
|
d:
|
2020-10-28 20:39:20 +00:00
|
|
|
- 0
|
|
|
|
- 1
|
2020-10-21 17:45:34 +00:00
|
|
|
e:
|
2020-10-28 20:39:20 +00:00
|
|
|
- true
|
|
|
|
- false
|
2020-10-21 17:45:34 +00:00
|
|
|
|
2022-12-28 07:07:35 +00:00
|
|
|
- name: Set fact
|
|
|
|
ansible.builtin.set_fact:
|
2020-10-21 17:45:34 +00:00
|
|
|
paths: "{{ lookup('ansible.utils.to_paths', a) }}"
|
|
|
|
|
|
|
|
# TASK [ansible.builtin.set_fact] ********************************************
|
|
|
|
# ok: [nxos101] => changed=false
|
|
|
|
# ansible_facts:
|
|
|
|
# paths:
|
|
|
|
# b.c.d[0]: 0
|
|
|
|
# b.c.d[1]: 1
|
|
|
|
# b.c.e[0]: true
|
|
|
|
# b.c.e[1]: false
|
|
|
|
|
|
|
|
- name: Use prepend to add the initial variable name
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
paths: "{{ lookup('ansible.utils.to_paths', a, prepend='a') }}"
|
|
|
|
# TASK [Use prepend to add the initial variable name] **************************
|
|
|
|
# ok: [nxos101] => changed=false
|
|
|
|
# ansible_facts:
|
|
|
|
# paths:
|
|
|
|
# a.b.c.d[0]: 0
|
|
|
|
# a.b.c.d[1]: 1
|
|
|
|
# a.b.c.e[0]: true
|
|
|
|
# a.b.c.e[1]: false
|
|
|
|
|
|
|
|
#### Using a complex object
|
|
|
|
|
|
|
|
# - name: Make an API call
|
2021-01-25 11:27:04 +00:00
|
|
|
# ansible.builtin.uri:
|
2020-10-21 17:45:34 +00:00
|
|
|
# url: "https://nxos101/restconf/data/openconfig-interfaces:interfaces"
|
|
|
|
# headers:
|
|
|
|
# accept: "application/yang.data+json"
|
|
|
|
# url_password: password
|
|
|
|
# url_username: admin
|
|
|
|
# validate_certs: False
|
|
|
|
# register: result
|
|
|
|
# delegate_to: localhost
|
|
|
|
|
|
|
|
# - name: Flatten the complex object
|
2021-01-25 11:27:04 +00:00
|
|
|
# ansible.builtin.set_fact:
|
2020-10-21 17:45:34 +00:00
|
|
|
# paths: "{{ lookup('ansible.utils.to_paths', result.json) }}"
|
|
|
|
|
|
|
|
# TASK [Flatten the complex object] ******************************************
|
|
|
|
# ok: [nxos101] => changed=false
|
|
|
|
# ansible_facts:
|
|
|
|
# paths:
|
|
|
|
# interfaces.interface[0].config.enabled: 'true'
|
|
|
|
# interfaces.interface[0].config.mtu: '1500'
|
|
|
|
# interfaces.interface[0].config.name: eth1/71
|
|
|
|
# interfaces.interface[0].config.type: ethernetCsmacd
|
|
|
|
# interfaces.interface[0].ethernet.config['auto-negotiate']: 'true'
|
|
|
|
# interfaces.interface[0].ethernet.state.counters['in-crc-errors']: '0'
|
|
|
|
# interfaces.interface[0].ethernet.state.counters['in-fragment-frames']: '0'
|
|
|
|
# interfaces.interface[0].ethernet.state.counters['in-jabber-frames']: '0'
|
|
|
|
# interfaces.interface[0].ethernet.state.counters['in-mac-control-frames']: '0'
|
|
|
|
# <...>
|