I have this list from a shell output.
- 192.168.20.76:3260,1054 iqn.1992-08.com.netapp:sn.f4bc76f43e2611e883e200a098d2174a:vs.6
- 192.168.21.126:3260,1056 iqn.1992-08.com.netapp:sn.f4bc76f43e2611e883e200a098d2174a:vs.6
- 192.168.21.125:3260,1055 iqn.1992-08.com.netapp:sn.f4bc76f43e2611e883e200a098d2174a:vs.6
- 192.168.20.75:3260,1053 iqn.1992-08.com.netapp:sn.f4bc76f43e2611e883e200a098d2174a:vs.6
- 192.168.22.20:3260,1052 iqn.1992-08.com.netapp:sn.f4bc76f43e2611e883e200a098d2174a:vs.6
- 192.168.22.19:3260,1051 iqn.1992-08.com.netapp:sn.f4bc76f43e2611e883e200a098d2174a:vs.6
I want to get both the IP and the iqn.xxxxx from the list when the IP is in the same vlan as the host.
I am able to create a list of the correct IP's but can't figure out how to also get the corresponding iqn.
Code:
- hosts: test_server
gather_facts: yes
tasks:
- name:
set_facts:
iscsi_vlan: '192.168.20.64/28'
- name: iscsiadm discovery
command: /usr/sbin/iscsiadm iscsiadm --mode discovery --type sendtargets --portal {{ storage_fqdn }}
register: iscsiadm_out
- name: facts
set_fact:
target_list: "{{ target_list + item | regex_findall('(^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})') | ipaddr( iscsi_vlan ) }}"
loop: "{{ iscsiadm_out.stdout_lines }}"
- name: target_list
debug:
var: target_list
target_list contains this. It matches the correct subnet using the ip_addr function.
ok: [test-server] =>
target_list:
- 192.168.20.76
- 192.168.20.75
Basically I end up with trying to search in a list with the contents of another list.
- I've tried with_subelements but it requires a string and a list
- I've tried to figure out how I can extract both the correct IP and the iqn from iscsiadm_out in one go with regex, but can't.
- I've contemplated turning iscsiadm_out into a json object and then use json_query, but I don't know how to do that.
How can I either use this list to extract the iqn from iscsiadm_out or maybe in a totally different way?
I understand I can use commands like grep and awk in the command module, but I don't like that option.
In my testing I have searched around here and elswhere on the Internet for hours. I'm a novice at Ansible and a total noob at python and jinja2, but I tried to investigate those paths too to no avail.