I'm trying to append a string to a list in ansible , so basically i'll be building a payload to delete few of the topology records in the F5 GTM network gear.
I was able to create one single list which includes all the output of the respective topology record. For the each line of the output i need to append with a string 'delete'.
- name: Lookup Topology Records
bigip_command:
user: admin
password: password
server: gtm.abc.com
commands: "list gtm topology | grep -i '{{ item }}'"
warn: no
validate_certs: no
register: topology_info
delegate_to: localhost
loop: "{{ gtm_pool }}"
- debug: var=topology_info
- name: Sanitize the Topology records of the Pool
set_fact:
clean_topology_info: "{{ clean_topology_info | default ([]) + item.stdout_lines }}"
loop: "{{ topology_info.results }}"
- debug: var=clean_topology_info
- name: Sanitized Topology Info
vars:
topology_item: "{{ item }}"
set_fact:
sanitized_topology_info: "{{ sanitized_topology_info | default ([]) + topology_item }}"
loop: "{{ clean_topology_info }}"
- name: Build payload to delete the Topology Record
set_fact:
topology_payload: "{{ topology_payload | default([]) + ['delete'] + item }}"
loop: "{{ clean_topology_info }}"
- debug: var=topology_payload
------------------------------------------------------------
Debug outputs(stdout_lines) as below :-
"gtm_pool": [
"test-poo1",
"test-pool2"
]
debug of "topology_info" :-
"stdout_lines": [
[
"gtm topology ldns: subnet 10.10.10.0/24 server: pool /Common/test-pool1 {",
"gtm topology ldns: subnet 10.8.22.0/24 server: pool /Common/test-pool1 {"
]
]
"stdout_lines": [
[
"gtm topology ldns: subnet 0.0.0.0/0 server: pool /Common/test-pool2 {"
]
debug of "clean_topology_info":-
"clean_topology_info": [
[
"gtm topology ldns: subnet 10.10.10.0/24 server: pool /Common/test-pool1 {",
"gtm topology ldns: subnet 10.8.22.0/24 server: pool /Common/test-pool1 {",
],
[
"gtm topology ldns: subnet 0.0.0.0/0 server: pool /Common/test-pool2 {",
]
]
debug of "sanitized_topology_info":-
"sanitized_topology_info": [
"gtm topology ldns: subnet 10.10.10.0/24 server: pool /Common/test-pool1 {",
"gtm topology ldns: subnet 10.8.22.0/24 server: pool /Common/test-pool1 {",
"gtm topology ldns: subnet 0.0.0.0/0 server: pool /Common/test-pool2 {"
]
debug of "topology_payload":-
"topology_payload": [
"delete",
"gtm topology ldns: subnet 10.10.10.0/24 server: pool /Common/test-pool1 {",
"gtm topology ldns: subnet 10.8.22.0/24 server: pool /Common/test-pool1 {",
"delete",
"gtm topology ldns: subnet 0.0.0.0/0 server: pool /Common/test-pool2 {"
]
Expected output of topology_payload should be like :-
Basically i need to append a string 'delete' infront of the each output.
"topology_payload": [
"delete gtm topology ldns: subnet 10.10.10.0/24 server: pool /Common/test-pool1 {",
"delete gtm topology ldns: subnet 10.8.22.0/24 server: pool /Common/test-pool1 {",
"delete gtm topology ldns: subnet 0.0.0.0/0 server: pool /Common/test-pool2 {"
]
Expected output of topology_payload should be like :-
Basically i need to append a string 'delete' infront of the each output.
topology_payload:
- "delete gtm topology ldns: subnet 10.10.10.0/24 server: pool /Common/test-pool1"
- "delete gtm topology ldns: subnet 10.8.22.0/24 server: pool /Common/test-pool1"
- "delete gtm topology ldns: subnet 0.0.0.0/0 server: pool /Common/test-pool2"