�
�Udac @` s d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d Z d d
l Z d d
l
Z
d d
l Z d d l m
Z
d Z d
� Z d
d � Z d � Z d � Z d
d
d � Z d � Z d � Z d � Z d � Z d � Z d � Z e d k re � n d
S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont previewt statust communityt supported_bys�
---
module: open_iscsi
author:
- Serge van Ginderachter (@srvg)
version_added: "1.4"
short_description: Manage iSCSI targets with Open-iSCSI
description:
- Discover targets on given portal, (dis)connect targets, mark targets to
manually or auto start, return device nodes of connected targets.
requirements:
- open_iscsi library and tools (iscsiadm)
options:
portal:
description:
- The IP address of the iSCSI target.
type: str
aliases: [ ip ]
port:
description:
- The port on which the iSCSI target process listens.
type: str
default: 3260
target:
description:
- The iSCSI target name.
type: str
aliases: [ name, targetname ]
login:
description:
- Whether the target node should be connected.
type: bool
aliases: [ state ]
node_auth:
description:
- The value for C(discovery.sendtargets.auth.authmethod).
type: str
default: CHAP
node_user:
description:
- The value for C(discovery.sendtargets.auth.username).
type: str
node_pass:
description:
- The value for C(discovery.sendtargets.auth.password).
type: str
auto_node_startup:
description:
- Whether the target node should be automatically connected at startup.
type: bool
aliases: [ automatic ]
discover:
description:
- Whether the list of target nodes on the portal should be
(re)discovered and added to the persistent iSCSI database.
- Keep in mind that C(iscsiadm) discovery resets configuration, like C(node.startup)
to manual, hence combined with C(auto_node_startup=yes) will always return
a changed state.
type: bool
show_nodes:
description:
- Whether the list of nodes in the persistent iSCSI database should be returned by the module.
type: bool
s�
- 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
# NOTE: Only works if exactly one target is exported to the initiator
- name: Discover targets on portal and login to the one available
open_iscsi:
portal: '{{ iscsi_target }}'
login: yes
discover: yes
- name: Connect to the named target, after updating the local persistent database (cache)
open_iscsi:
login: yes
target: iqn.1986-03.com.sun:02:f8c1f9e0-c3ec-ec84-c9c9-8bfb0cd5de3d
- name: Disconnect from the cached named target
open_iscsi:
login: no
target: iqn.1986-03.com.sun:02:f8c1f9e0-c3ec-ec84-c9c9-8bfb0cd5de3d
N( t
AnsibleModulet iscsiadmc C` s | j � | j � | | k S( N( t sort( t l1t l2( ( sE /usr/lib/python2.7/site-packages/ansible/modules/system/open_iscsi.pyt compare_nodelistsq s
c C` s' d t } | j | � \ } } } | d k r� | j � } g } x� | D]� } | j � } t | � d k r� | j d d d | � n | d }
| d j d � } | d } | d k s� | | k rG | j |
� qG qG WnI | d k s� | d
k rd | k rg } n | j d | d | d | � | S(
Ns %s --mode nodei i t msgs error parsing outputt cmdi t :i i� s o records foundt rc( t iscsiadm_cmdt run_commandt
splitlinest splitt lent fail_jsont Nonet append( t modulet portalR R t outt errt linest nodest linet partst targett
target_portal( ( sE /usr/lib/python2.7/site-packages/ansible/modules/system/open_iscsi.pyt iscsi_get_cached_nodesw s$
$ c C` sZ d t | | f } | j | � \ } } } | d k rV | j d | d | d | � n d S( Ns5 %s --mode discovery --type sendtargets --portal %s:%si R R R ( R R R ( R R t portR R R R ( ( sE /usr/lib/python2.7/site-packages/ansible/modules/system/open_iscsi.pyt iscsi_discover� s c C` sh d t } | j | � \ } } } | d k r8 | | k S| d k rH t S| j d | d | d | � d S( Ns %s --mode sessioni i R R R ( R R t FalseR ( R R"