�
�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
Z d d l
Z
d d l Z d d l Z d d l
m Z d d
l m Z d � Z d � Z d � Z d � Z d � Z d d � Z d � Z d � Z d � Z e d k r e � n d S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont stableinterfacet statust communityt supported_bys�
---
module: interfaces_file
short_description: Tweak settings in /etc/network/interfaces files
extends_documentation_fragment: files
description:
- Manage (add, remove, change) individual interface options in an interfaces-style file without having
to manage the file as a whole with, say, M(template) or M(assemble). Interface has to be presented in a file.
- Read information about interfaces from interfaces-styled files
version_added: "2.4"
options:
dest:
description:
- Path to the interfaces file
default: /etc/network/interfaces
iface:
description:
- Name of the interface, required for value changes or option remove
address_family:
description:
- Address family of the interface, useful if same interface name is used for both inet and inet6
version_added: "2.8"
option:
description:
- Name of the option, required for value changes or option remove
value:
description:
- If I(option) is not presented for the I(interface) and I(state) is C(present) option will be added.
If I(option) already exists and is not C(pre-up), C(up), C(post-up) or C(down), it's value will be updated.
C(pre-up), C(up), C(post-up) and C(down) options can't be updated, only adding new options, removing existing
ones or cleaning the whole option set are supported
backup:
description:
- Create a backup file including the timestamp information so you can get
the original file back if you somehow clobbered it incorrectly.
type: bool
default: 'no'
state:
description:
- If set to C(absent) the option or section will be removed if present instead of created.
default: "present"
choices: [ "present", "absent" ]
notes:
- If option is defined multiple times last one will be updated but all will be deleted in case of an absent state
requirements: []
author: "Roman Belyakovsky (@hryamzik)"
s�
dest:
description: destination file/path
returned: success
type: str
sample: "/etc/network/interfaces"
ifaces:
description: interfaces dictionary
returned: success
type: complex
contains:
ifaces:
description: interface dictionary
returned: success
type: dict
contains:
eth0:
description: Name of the interface
returned: success
type: dict
contains:
address_family:
description: interface address family
returned: success
type: str
sample: "inet"
method:
description: interface method
returned: success
type: str
sample: "manual"
mtu:
description: other options, all values returned as strings
returned: success
type: str
sample: "1500"
pre-up:
description: list of C(pre-up) scripts
returned: success
type: list
sample:
- "route add -net 10.10.10.0/24 gw 10.10.10.1 dev eth1"
- "route add -net 10.10.11.0/24 gw 10.10.11.1 dev eth2"
up:
description: list of C(up) scripts
returned: success
type: list
sample:
- "route add -net 10.10.10.0/24 gw 10.10.10.1 dev eth1"
- "route add -net 10.10.11.0/24 gw 10.10.11.1 dev eth2"
post-up:
description: list of C(post-up) scripts
returned: success
type: list
sample:
- "route add -net 10.10.10.0/24 gw 10.10.10.1 dev eth1"
- "route add -net 10.10.11.0/24 gw 10.10.11.1 dev eth2"
down:
description: list of C(down) scripts
returned: success
type: list
sample:
- "route del -net 10.10.10.0/24 gw 10.10.10.1 dev eth1"
- "route del -net 10.10.11.0/24 gw 10.10.11.1 dev eth2"
...
s�
# Set eth1 mtu configuration value to 8000
- interfaces_file:
dest: /etc/network/interfaces.d/eth1.cfg
iface: eth1
option: mtu
value: 8000
backup: yes
state: present
register: eth1_cfg
N( t
AnsibleModule( t to_bytesc C` s i | d 6d d 6S( Nt linet unknownt line_type( ( R
( ( sJ /usr/lib/python2.7/site-packages/ansible/modules/system/interfaces_file.pyt lineDict� s c C` s. i | d 6| d 6| d 6| d 6d d 6| d 6S( NR
t ifacet optiont valueR t address_family( ( R
R R R R ( ( sJ /usr/lib/python2.7/site-packages/ansible/modules/system/interfaces_file.pyt
optionDict� s c C` s� t j d � } x | j | � D] } q W| j � } | j � d } | j | � } t | � } t j d | | | � j � | | } | | | !S( Ns \s+i s \s( t ret compilet finditert startt splitt findt lent searcht end( t st spaceRet mt valueEndR t optionStartt optionLent
valueStart( ( sJ /usr/lib/python2.7/site-packages/ansible/modules/system/interfaces_file.pyt getValueFromLine� s (c C` s t | d � } t | | � S( Nt r( t opent read_interfaces_lines( t modulet filenamet f( ( sJ /usr/lib/python2.7/site-packages/ansible/modules/system/interfaces_file.pyt read_interfaces_file� s c
C` s� g } i } d } d } x�| D]�} | d 7} | j � } t | � d k rf | j t | � � q n | d d d k r� | j t | � � q n | d d k r� | j t | � � d } q | d d k r� | j t | � � d } q | d d k r| j t | � � d } q | d d k rC| j t | � � d } q | d d
k r,i g d 6g d 6g d
6g d 6} | d } y | d | d <Wn t k
r�d | d <n X| d }
y | d | d <Wn t k
r�d | d <n X| | | <| j i | d 6| d
6d
d 6| d 6|
d 6� d } q | d d k rX| j t | � � d } q | d j d � r�| j t | � � d } q | d d k r�| j t | � � d } q | d d k r�| j t | � � d } q | d k rM| d } t | � } | j t | | | | |
� � | d k r@| | j | � q�| | | <q | d k ro| j t | � � q | d k r�| j t | � � q | j d d | | f � d Sq W| | f S( Ni i t #t mappingt MAPPINGt sourcet NONEs
source-dirs source-directoryR s pre-upt upt downs post-upi R i t methodR
R t paramst IFACEt autos allow-s no-auto-downs
no-scriptst msgs misplaced option %s in line %d( s pre-upR0 R1 s post-up( NN(
t NoneR R t appendR
t
IndexErrort
startswithR# R t fail_json(
R'