From 2aa84f07f11dfe2cfdfa22ef2f4da09d71ae2a1b Mon Sep 17 00:00:00 2001 From: FatMinMin Date: Fri, 12 Jun 2020 19:38:41 +0800 Subject: [PATCH] Do domain resolution for portal (#461) * Do domain resolution for portal iscsiadm support domain resolution (ex: iscsiadm -m discovery -t sendtargets -p iscsi.chiehmin.com). However, open_iscsi module will try to match the portal with discovered results which will never matched cause the discovered results use IP to represent node. This patch do portal DNS resolution first to solve this situation. Signed-off-by: Chieh-Min Wang * Update changelogs/fragments/461-resolve-domain-for-iscsi-portal.yml Co-authored-by: Andrew Klychkov Co-authored-by: Andrew Klychkov --- .../461-resolve-domain-for-iscsi-portal.yml | 2 ++ plugins/modules/system/open_iscsi.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/461-resolve-domain-for-iscsi-portal.yml diff --git a/changelogs/fragments/461-resolve-domain-for-iscsi-portal.yml b/changelogs/fragments/461-resolve-domain-for-iscsi-portal.yml new file mode 100644 index 0000000000..071501ce82 --- /dev/null +++ b/changelogs/fragments/461-resolve-domain-for-iscsi-portal.yml @@ -0,0 +1,2 @@ +minor_changes: +- open_iscsi - allow ``portal`` parameter to be a domain name by resolving the portal ip address beforehand (https://github.com/ansible-collections/community.general/pull/461). diff --git a/plugins/modules/system/open_iscsi.py b/plugins/modules/system/open_iscsi.py index df6b9ea373..f109f9b8c6 100644 --- a/plugins/modules/system/open_iscsi.py +++ b/plugins/modules/system/open_iscsi.py @@ -21,7 +21,7 @@ requirements: options: portal: description: - - The IP address of the iSCSI target. + - The domain name or IP address of the iSCSI target. type: str aliases: [ ip ] port: @@ -72,11 +72,17 @@ options: ''' EXAMPLES = r''' +- name: Perform a discovery on sun.com and show available target nodes + open_iscsi: + show_nodes: yes + discover: yes + portal: sun.com + - name: Perform a discovery on 10.1.2.3 and show available target nodes open_iscsi: show_nodes: yes discover: yes - portal: 10.1.2.3 + ip: 10.1.2.3 # NOTE: Only works if exactly one target is exported to the initiator - name: Discover targets on portal and login to the one available @@ -98,6 +104,7 @@ EXAMPLES = r''' import glob import os +import socket import time from ansible.module_utils.basic import AnsibleModule @@ -270,6 +277,12 @@ def main(): # parameters portal = module.params['portal'] + if portal: + try: + portal = socket.getaddrinfo(portal, None)[0][4][0] + except socket.gaierror: + module.fail_json(msg="Portal address is incorrect") + target = module.params['target'] port = module.params['port'] login = module.params['login']