@ -30,7 +30,6 @@ description:
options :
options :
state :
state :
required : True
required : True
default : " present "
choices : [ present , absent ]
choices : [ present , absent ]
description :
description :
- Whether the device should exist or not , taking action if the state is different from what is stated .
- Whether the device should exist or not , taking action if the state is different from what is stated .
@ -41,25 +40,14 @@ options:
description :
description :
- Whether the service should start on boot . B ( At least one of state and enabled are required . )
- Whether the service should start on boot . B ( At least one of state and enabled are required . )
- Whether the connection profile can be automatically activated ( default : yes )
- Whether the connection profile can be automatically activated ( default : yes )
action :
conn_name :
required : False
default : None
choices : [ add , modify , show , up , down ]
description :
- Set to ' add ' if you want to add a connection .
- Set to ' modify ' if you want to modify a connection . Modify one or more properties in the connection profile .
- Set to ' delete ' if you want to delete a connection . Delete a configured connection . The connection to be deleted is identified by its name ' cfname ' .
- Set to ' show ' if you want to show a connection . Will show all devices unless ' cfname ' is set .
- Set to ' up ' if you want to bring a connection up . Requires ' cfname ' to be set .
- Set to ' down ' if you want to bring a connection down . Requires ' cfname ' to be set .
cname :
required : True
required : True
default : None
default : None
description :
description :
- Where CNAME will be the name used to call the connection . when not provided a default name is generated : < type > [ - < ifname > ] [ - < num > ]
- Where conn_name will be the name used to call the connection . when not provided a default name is generated : < type > [ - < ifname > ] [ - < num > ]
ifname :
ifname :
required : False
required : False
default : c name
default : conn_name
description :
description :
- Where INAME will be the what we call the interface name . Required with ' up ' , ' down ' modifiers .
- Where INAME will be the what we call the interface name . Required with ' up ' , ' down ' modifiers .
- interface to bind the connection to . The connection will only be applicable to this interface name .
- interface to bind the connection to . The connection will only be applicable to this interface name .
@ -80,7 +68,7 @@ options:
required : False
required : False
default : None
default : None
description :
description :
- master < master ( ifname , or connection UUID or c name) of bridge , team , bond master connection profile .
- master < master ( ifname , or connection UUID or c onn_ name) of bridge , team , bond master connection profile .
ip4 :
ip4 :
required : False
required : False
default : None
default : None
@ -241,32 +229,32 @@ tenant_gw: "172.100.0.254"
#Team vars
#Team vars
nmcli_team :
nmcli_team :
- { c name: ' tenant ' , ip4 : " {{ tenant_ip}} " , gw4 : " {{ tenant_gw}} " }
- { c onn_ name: ' tenant ' , ip4 : " {{ tenant_ip}} " , gw4 : " {{ tenant_gw}} " }
- { c name: ' external ' , ip4 : " {{ external_ip}} " , gw4 : " {{ external_gw}} " }
- { c onn_ name: ' external ' , ip4 : " {{ external_ip}} " , gw4 : " {{ external_gw}} " }
- { c name: ' storage ' , ip4 : " {{ storage_ip}} " , gw4 : " {{ storage_gw}} " }
- { c onn_ name: ' storage ' , ip4 : " {{ storage_ip}} " , gw4 : " {{ storage_gw}} " }
nmcli_team_slave :
nmcli_team_slave :
- { c name: ' em1 ' , ifname : ' em1 ' , master : ' tenant ' }
- { c onn_ name: ' em1 ' , ifname : ' em1 ' , master : ' tenant ' }
- { c name: ' em2 ' , ifname : ' em2 ' , master : ' tenant ' }
- { c onn_ name: ' em2 ' , ifname : ' em2 ' , master : ' tenant ' }
- { c name: ' p2p1 ' , ifname : ' p2p1 ' , master : ' storage ' }
- { c onn_ name: ' p2p1 ' , ifname : ' p2p1 ' , master : ' storage ' }
- { c name: ' p2p2 ' , ifname : ' p2p2 ' , master : ' external ' }
- { c onn_ name: ' p2p2 ' , ifname : ' p2p2 ' , master : ' external ' }
#bond vars
#bond vars
nmcli_bond :
nmcli_bond :
- { c name: ' tenant ' , ip4 : " {{ tenant_ip}} " , gw4 : ' ' , mode : ' balance-rr ' }
- { c onn_ name: ' tenant ' , ip4 : " {{ tenant_ip}} " , gw4 : ' ' , mode : ' balance-rr ' }
- { c name: ' external ' , ip4 : " {{ external_ip}} " , gw4 : ' ' , mode : ' balance-rr ' }
- { c onn_ name: ' external ' , ip4 : " {{ external_ip}} " , gw4 : ' ' , mode : ' balance-rr ' }
- { c name: ' storage ' , ip4 : " {{ storage_ip}} " , gw4 : " {{ storage_gw}} " , mode : ' balance-rr ' }
- { c onn_ name: ' storage ' , ip4 : " {{ storage_ip}} " , gw4 : " {{ storage_gw}} " , mode : ' balance-rr ' }
nmcli_bond_slave :
nmcli_bond_slave :
- { c name: ' em1 ' , ifname : ' em1 ' , master : ' tenant ' }
- { c onn_ name: ' em1 ' , ifname : ' em1 ' , master : ' tenant ' }
- { c name: ' em2 ' , ifname : ' em2 ' , master : ' tenant ' }
- { c onn_ name: ' em2 ' , ifname : ' em2 ' , master : ' tenant ' }
- { c name: ' p2p1 ' , ifname : ' p2p1 ' , master : ' storage ' }
- { c onn_ name: ' p2p1 ' , ifname : ' p2p1 ' , master : ' storage ' }
- { c name: ' p2p2 ' , ifname : ' p2p2 ' , master : ' external ' }
- { c onn_ name: ' p2p2 ' , ifname : ' p2p2 ' , master : ' external ' }
#ethernet vars
#ethernet vars
nmcli_ethernet :
nmcli_ethernet :
- { c name: ' em1 ' , ifname : ' em1 ' , ip4 : " {{ tenant_ip}} " , gw4 : " {{ tenant_gw}} " }
- { c onn_ name: ' em1 ' , ifname : ' em1 ' , ip4 : " {{ tenant_ip}} " , gw4 : " {{ tenant_gw}} " }
- { c name: ' em2 ' , ifname : ' em2 ' , ip4 : " {{ tenant_ip1}} " , gw4 : " {{ tenant_gw}} " }
- { c onn_ name: ' em2 ' , ifname : ' em2 ' , ip4 : " {{ tenant_ip1}} " , gw4 : " {{ tenant_gw}} " }
- { c name: ' p2p1 ' , ifname : ' p2p1 ' , ip4 : " {{ storage_ip}} " , gw4 : " {{ storage_gw}} " }
- { c onn_ name: ' p2p1 ' , ifname : ' p2p1 ' , ip4 : " {{ storage_ip}} " , gw4 : " {{ storage_gw}} " }
- { c name: ' p2p2 ' , ifname : ' p2p2 ' , ip4 : " {{ external_ip}} " , gw4 : " {{ external_gw}} " }
- { c onn_ name: ' p2p2 ' , ifname : ' p2p2 ' , ip4 : " {{ external_ip}} " , gw4 : " {{ external_gw}} " }
` ` `
` ` `
### host_vars
### host_vars
@ -296,30 +284,30 @@ tenant_ip: "192.168.200.21/23"
- policycoreutils - python
- policycoreutils - python
##### Working with all cloud nodes - Teaming
##### Working with all cloud nodes - Teaming
- name : try nmcli add team - c name only & ip4 gw4
- name : try nmcli add team - c onn_ name only & ip4 gw4
nmcli : type = team c name= { { item . c name} } ip4 = { { item . ip4 } } gw4 = { { item . gw4 } } state = present
nmcli : type = team c onn_ name= { { item . c onn_ name} } ip4 = { { item . ip4 } } gw4 = { { item . gw4 } } state = present
with_items :
with_items :
- " {{ nmcli_team}} "
- " {{ nmcli_team}} "
- name : try nmcli add teams - slave
- name : try nmcli add teams - slave
nmcli : type = team - slave c name= { { item . c name} } ifname = { { item . ifname } } master = { { item . master } } state = present
nmcli : type = team - slave c onn_ name= { { item . c onn_ name} } ifname = { { item . ifname } } master = { { item . master } } state = present
with_items :
with_items :
- " {{ nmcli_team_slave}} "
- " {{ nmcli_team_slave}} "
###### Working with all cloud nodes - Bonding
###### Working with all cloud nodes - Bonding
# - name: try nmcli add bond - c name only & ip4 gw4 mode
# - name: try nmcli add bond - c onn_ name only & ip4 gw4 mode
# nmcli: type=bond c name={{item.cname}} ip4={{item.ip4}} gw4={{item.gw4}} mode={{item.mode}} state=present
# nmcli: type=bond c onn_ name={{item.conn_ name}} ip4={{item.ip4}} gw4={{item.gw4}} mode={{item.mode}} state=present
# with_items:
# with_items:
# - "{{nmcli_bond}}"
# - "{{nmcli_bond}}"
#
#
# - name: try nmcli add bond-slave
# - name: try nmcli add bond-slave
# nmcli: type=bond-slave c name={{item.cname}} ifname={{item.ifname}} master={{item.master}} state=present
# nmcli: type=bond-slave c onn_ name={{item.conn_ name}} ifname={{item.ifname}} master={{item.master}} state=present
# with_items:
# with_items:
# - "{{nmcli_bond_slave}}"
# - "{{nmcli_bond_slave}}"
##### Working with all cloud nodes - Ethernet
##### Working with all cloud nodes - Ethernet
# - name: nmcli add Ethernet - c name only & ip4 gw4
# - name: nmcli add Ethernet - c onn_ name only & ip4 gw4
# nmcli: type=ethernet c name={{item.cname}} ip4={{item.ip4}} gw4={{item.gw4}} state=present
# nmcli: type=ethernet c onn_ name={{item.conn_ name}} ip4={{item.ip4}} gw4={{item.gw4}} state=present
# with_items:
# with_items:
# - "{{nmcli_ethernet}}"
# - "{{nmcli_ethernet}}"
` ` `
` ` `
@ -333,41 +321,41 @@ tenant_ip: "192.168.200.21/23"
tasks :
tasks :
- name : try nmcli del team - multiple
- name : try nmcli del team - multiple
nmcli : c name= { { item . c name} } state = absent
nmcli : c onn_ name= { { item . c onn_ name} } state = absent
with_items :
with_items :
- { c name: ' em1 ' }
- { c onn_ name: ' em1 ' }
- { c name: ' em2 ' }
- { c onn_ name: ' em2 ' }
- { c name: ' p1p1 ' }
- { c onn_ name: ' p1p1 ' }
- { c name: ' p1p2 ' }
- { c onn_ name: ' p1p2 ' }
- { c name: ' p2p1 ' }
- { c onn_ name: ' p2p1 ' }
- { c name: ' p2p2 ' }
- { c onn_ name: ' p2p2 ' }
- { c name: ' tenant ' }
- { c onn_ name: ' tenant ' }
- { c name: ' storage ' }
- { c onn_ name: ' storage ' }
- { c name: ' external ' }
- { c onn_ name: ' external ' }
- { c name: ' team-em1 ' }
- { c onn_ name: ' team-em1 ' }
- { c name: ' team-em2 ' }
- { c onn_ name: ' team-em2 ' }
- { c name: ' team-p1p1 ' }
- { c onn_ name: ' team-p1p1 ' }
- { c name: ' team-p1p2 ' }
- { c onn_ name: ' team-p1p2 ' }
- { c name: ' team-p2p1 ' }
- { c onn_ name: ' team-p2p1 ' }
- { c name: ' team-p2p2 ' }
- { c onn_ name: ' team-p2p2 ' }
` ` `
` ` `
# To add an Ethernet connection with static IP configuration, issue a command as follows
# To add an Ethernet connection with static IP configuration, issue a command as follows
- nmcli : c name= my - eth1 ifname = eth1 type = ethernet ip4 = 192.168 .100 .100 / 24 gw4 = 192.168 .100 .1 state = present
- nmcli : c onn_ name= my - eth1 ifname = eth1 type = ethernet ip4 = 192.168 .100 .100 / 24 gw4 = 192.168 .100 .1 state = present
# To add an Team connection with static IP configuration, issue a command as follows
# To add an Team connection with static IP configuration, issue a command as follows
- nmcli : c name= my - team1 ifname = my - team1 type = team ip4 = 192.168 .100 .100 / 24 gw4 = 192.168 .100 .1 state = present enabled = yes
- nmcli : c onn_ name= my - team1 ifname = my - team1 type = team ip4 = 192.168 .100 .100 / 24 gw4 = 192.168 .100 .1 state = present enabled = yes
# Optionally, at the same time specify IPv6 addresses for the device as follows:
# Optionally, at the same time specify IPv6 addresses for the device as follows:
- nmcli : c name= my - eth1 ifname = eth1 type = ethernet ip4 = 192.168 .100 .100 / 24 gw4 = 192.168 .100 .1 ip6 = abbe : : cafe gw6 = 2001 : db8 : : 1 state = present
- nmcli : c onn_ name= my - eth1 ifname = eth1 type = ethernet ip4 = 192.168 .100 .100 / 24 gw4 = 192.168 .100 .1 ip6 = abbe : : cafe gw6 = 2001 : db8 : : 1 state = present
# To add two IPv4 DNS server addresses:
# To add two IPv4 DNS server addresses:
- nmcli : c name= my - eth1 dns4 = [ " 8.8.8.8 " , " 8.8.4.4 " ] state = present
- nmcli : c onn_ name= my - eth1 dns4 = [ " 8.8.8.8 " , " 8.8.4.4 " ] state = present
# To make a profile usable for all compatible Ethernet interfaces, issue a command as follows
# To make a profile usable for all compatible Ethernet interfaces, issue a command as follows
- nmcli : ctype = ethernet name = my - eth1 ifname = " * " state = present
- nmcli : ctype = ethernet name = my - eth1 ifname = " * " state = present
# To change the property of a setting e.g. MTU, issue a command as follows:
# To change the property of a setting e.g. MTU, issue a command as follows:
- nmcli : c name= my - eth1 mtu = 9000 state = present
- nmcli : c onn_ name= my - eth1 mtu = 9000 state = present
Exit Status ' s:
Exit Status ' s:
- nmcli exits with status 0 if it succeeds , a value greater than 0 is
- nmcli exits with status 0 if it succeeds , a value greater than 0 is
@ -438,15 +426,12 @@ class Nmcli(object):
120 : " Failed "
120 : " Failed "
}
}
def __new__ ( cls , * args , * * kwargs ) :
return load_platform_subclass ( Nmcli , args , kwargs )
def __init__ ( self , module ) :
def __init__ ( self , module ) :
self . module = module
self . module = module
self . state = module . params [ ' state ' ]
self . state = module . params [ ' state ' ]
self . enabled = module . params [ ' enabled ' ]
self . enabled = module . params [ ' enabled ' ]
self . action = module . params [ ' action ' ]
self . conn_name = module . params [ ' conn_name ' ]
self . cname = module . params [ ' cname ' ]
self . master = module . params [ ' master ' ]
self . master = module . params [ ' master ' ]
self . autoconnect = module . params [ ' autoconnect ' ]
self . autoconnect = module . params [ ' autoconnect ' ]
self . ifname = module . params [ ' ifname ' ]
self . ifname = module . params [ ' ifname ' ]
@ -570,7 +555,7 @@ class Nmcli(object):
connections = self . list_connection_info ( )
connections = self . list_connection_info ( )
for con_item in connections :
for con_item in connections :
if self . c name== con_item :
if self . c onn_ name== con_item :
return True
return True
def down_connection ( self ) :
def down_connection ( self ) :
@ -578,14 +563,14 @@ class Nmcli(object):
# if self.connection_exists():
# if self.connection_exists():
cmd . append ( ' con ' )
cmd . append ( ' con ' )
cmd . append ( ' down ' )
cmd . append ( ' down ' )
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
return self . execute_command ( cmd )
return self . execute_command ( cmd )
def up_connection ( self ) :
def up_connection ( self ) :
cmd = [ self . module . get_bin_path ( ' nmcli ' , True ) ]
cmd = [ self . module . get_bin_path ( ' nmcli ' , True ) ]
cmd . append ( ' con ' )
cmd . append ( ' con ' )
cmd . append ( ' up ' )
cmd . append ( ' up ' )
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
return self . execute_command ( cmd )
return self . execute_command ( cmd )
def create_connection_team ( self ) :
def create_connection_team ( self ) :
@ -596,15 +581,15 @@ class Nmcli(object):
cmd . append ( ' type ' )
cmd . append ( ' type ' )
cmd . append ( ' team ' )
cmd . append ( ' team ' )
cmd . append ( ' con-name ' )
cmd . append ( ' con-name ' )
if self . c name is not None :
if self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
elif self . ifname is not None :
elif self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
cmd . append ( ' ifname ' )
cmd . append ( ' ifname ' )
if self . ifname is not None :
if self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
elif self . c name is not None :
elif self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
if self . ip4 is not None :
if self . ip4 is not None :
cmd . append ( ' ip4 ' )
cmd . append ( ' ip4 ' )
cmd . append ( self . ip4 )
cmd . append ( self . ip4 )
@ -627,7 +612,7 @@ class Nmcli(object):
# format for modifying team interface
# format for modifying team interface
cmd . append ( ' con ' )
cmd . append ( ' con ' )
cmd . append ( ' mod ' )
cmd . append ( ' mod ' )
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
if self . ip4 is not None :
if self . ip4 is not None :
cmd . append ( ' ipv4.address ' )
cmd . append ( ' ipv4.address ' )
cmd . append ( self . ip4 )
cmd . append ( self . ip4 )
@ -660,17 +645,17 @@ class Nmcli(object):
cmd . append ( ' type ' )
cmd . append ( ' type ' )
cmd . append ( self . type )
cmd . append ( self . type )
cmd . append ( ' con-name ' )
cmd . append ( ' con-name ' )
if self . c name is not None :
if self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
elif self . ifname is not None :
elif self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
cmd . append ( ' ifname ' )
cmd . append ( ' ifname ' )
if self . ifname is not None :
if self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
elif self . c name is not None :
elif self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
cmd . append ( ' master ' )
cmd . append ( ' master ' )
if self . c name is not None :
if self . c onn_ name is not None :
cmd . append ( self . master )
cmd . append ( self . master )
# if self.mtu is not None:
# if self.mtu is not None:
# cmd.append('802-3-ethernet.mtu')
# cmd.append('802-3-ethernet.mtu')
@ -682,7 +667,7 @@ class Nmcli(object):
# format for modifying team-slave interface
# format for modifying team-slave interface
cmd . append ( ' con ' )
cmd . append ( ' con ' )
cmd . append ( ' mod ' )
cmd . append ( ' mod ' )
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
cmd . append ( ' connection.master ' )
cmd . append ( ' connection.master ' )
cmd . append ( self . master )
cmd . append ( self . master )
if self . mtu is not None :
if self . mtu is not None :
@ -698,15 +683,15 @@ class Nmcli(object):
cmd . append ( ' type ' )
cmd . append ( ' type ' )
cmd . append ( ' bond ' )
cmd . append ( ' bond ' )
cmd . append ( ' con-name ' )
cmd . append ( ' con-name ' )
if self . c name is not None :
if self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
elif self . ifname is not None :
elif self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
cmd . append ( ' ifname ' )
cmd . append ( ' ifname ' )
if self . ifname is not None :
if self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
elif self . c name is not None :
elif self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
if self . ip4 is not None :
if self . ip4 is not None :
cmd . append ( ' ip4 ' )
cmd . append ( ' ip4 ' )
cmd . append ( self . ip4 )
cmd . append ( self . ip4 )
@ -747,7 +732,7 @@ class Nmcli(object):
# format for modifying bond interface
# format for modifying bond interface
cmd . append ( ' con ' )
cmd . append ( ' con ' )
cmd . append ( ' mod ' )
cmd . append ( ' mod ' )
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
if self . ip4 is not None :
if self . ip4 is not None :
cmd . append ( ' ipv4.address ' )
cmd . append ( ' ipv4.address ' )
cmd . append ( self . ip4 )
cmd . append ( self . ip4 )
@ -779,17 +764,17 @@ class Nmcli(object):
cmd . append ( ' type ' )
cmd . append ( ' type ' )
cmd . append ( ' bond-slave ' )
cmd . append ( ' bond-slave ' )
cmd . append ( ' con-name ' )
cmd . append ( ' con-name ' )
if self . c name is not None :
if self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
elif self . ifname is not None :
elif self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
cmd . append ( ' ifname ' )
cmd . append ( ' ifname ' )
if self . ifname is not None :
if self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
elif self . c name is not None :
elif self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
cmd . append ( ' master ' )
cmd . append ( ' master ' )
if self . c name is not None :
if self . c onn_ name is not None :
cmd . append ( self . master )
cmd . append ( self . master )
return cmd
return cmd
@ -798,7 +783,7 @@ class Nmcli(object):
# format for modifying bond-slave interface
# format for modifying bond-slave interface
cmd . append ( ' con ' )
cmd . append ( ' con ' )
cmd . append ( ' mod ' )
cmd . append ( ' mod ' )
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
cmd . append ( ' connection.master ' )
cmd . append ( ' connection.master ' )
cmd . append ( self . master )
cmd . append ( self . master )
return cmd
return cmd
@ -807,22 +792,22 @@ class Nmcli(object):
cmd = [ self . module . get_bin_path ( ' nmcli ' , True ) ]
cmd = [ self . module . get_bin_path ( ' nmcli ' , True ) ]
# format for creating ethernet interface
# format for creating ethernet interface
# To add an Ethernet connection with static IP configuration, issue a command as follows
# To add an Ethernet connection with static IP configuration, issue a command as follows
# - nmcli: name=add c name=my-eth1 ifname=eth1 type=ethernet ip4=192.168.100.100/24 gw4=192.168.100.1 state=present
# - nmcli: name=add c onn_ name=my-eth1 ifname=eth1 type=ethernet ip4=192.168.100.100/24 gw4=192.168.100.1 state=present
# nmcli con add con-name my-eth1 ifname eth1 type ethernet ip4 192.168.100.100/24 gw4 192.168.100.1
# nmcli con add con-name my-eth1 ifname eth1 type ethernet ip4 192.168.100.100/24 gw4 192.168.100.1
cmd . append ( ' con ' )
cmd . append ( ' con ' )
cmd . append ( ' add ' )
cmd . append ( ' add ' )
cmd . append ( ' type ' )
cmd . append ( ' type ' )
cmd . append ( ' ethernet ' )
cmd . append ( ' ethernet ' )
cmd . append ( ' con-name ' )
cmd . append ( ' con-name ' )
if self . c name is not None :
if self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
elif self . ifname is not None :
elif self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
cmd . append ( ' ifname ' )
cmd . append ( ' ifname ' )
if self . ifname is not None :
if self . ifname is not None :
cmd . append ( self . ifname )
cmd . append ( self . ifname )
elif self . c name is not None :
elif self . c onn_ name is not None :
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
if self . ip4 is not None :
if self . ip4 is not None :
cmd . append ( ' ip4 ' )
cmd . append ( ' ip4 ' )
cmd . append ( self . ip4 )
cmd . append ( self . ip4 )
@ -844,11 +829,11 @@ class Nmcli(object):
cmd = [ self . module . get_bin_path ( ' nmcli ' , True ) ]
cmd = [ self . module . get_bin_path ( ' nmcli ' , True ) ]
# format for modifying ethernet interface
# format for modifying ethernet interface
# To add an Ethernet connection with static IP configuration, issue a command as follows
# To add an Ethernet connection with static IP configuration, issue a command as follows
# - nmcli: name=add c name=my-eth1 ifname=eth1 type=ethernet ip4=192.168.100.100/24 gw4=192.168.100.1 state=present
# - nmcli: name=add c onn_ name=my-eth1 ifname=eth1 type=ethernet ip4=192.168.100.100/24 gw4=192.168.100.1 state=present
# nmcli con add con-name my-eth1 ifname eth1 type ethernet ip4 192.168.100.100/24 gw4 192.168.100.1
# nmcli con add con-name my-eth1 ifname eth1 type ethernet ip4 192.168.100.100/24 gw4 192.168.100.1
cmd . append ( ' con ' )
cmd . append ( ' con ' )
cmd . append ( ' mod ' )
cmd . append ( ' mod ' )
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
if self . ip4 is not None :
if self . ip4 is not None :
cmd . append ( ' ipv4.address ' )
cmd . append ( ' ipv4.address ' )
cmd . append ( self . ip4 )
cmd . append ( self . ip4 )
@ -955,7 +940,7 @@ class Nmcli(object):
cmd = [ self . module . get_bin_path ( ' nmcli ' , True ) ]
cmd = [ self . module . get_bin_path ( ' nmcli ' , True ) ]
cmd . append ( ' con ' )
cmd . append ( ' con ' )
cmd . append ( ' del ' )
cmd . append ( ' del ' )
cmd . append ( self . c name)
cmd . append ( self . c onn_ name)
return self . execute_command ( cmd )
return self . execute_command ( cmd )
def modify_connection ( self ) :
def modify_connection ( self ) :
@ -982,9 +967,8 @@ def main():
module = AnsibleModule (
module = AnsibleModule (
argument_spec = dict (
argument_spec = dict (
enabled = dict ( required = False , default = None , choices = [ ' yes ' , ' no ' ] , type = ' str ' ) ,
enabled = dict ( required = False , default = None , choices = [ ' yes ' , ' no ' ] , type = ' str ' ) ,
action = dict ( required = False , default = None , choices = [ ' add ' , ' mod ' , ' show ' , ' up ' , ' down ' , ' del ' ] , type = ' str ' ) ,
state = dict ( required = True , choices = [ ' present ' , ' absent ' ] , type = ' str ' ) ,
state = dict ( required = True , default = None , choices = [ ' present ' , ' absent ' ] , type = ' str ' ) ,
conn_name = dict ( required = False , type = ' str ' ) ,
cname = dict ( required = False , type = ' str ' ) ,
master = dict ( required = False , default = None , type = ' str ' ) ,
master = dict ( required = False , default = None , type = ' str ' ) ,
autoconnect = dict ( required = False , default = None , choices = [ ' yes ' , ' no ' ] , type = ' str ' ) ,
autoconnect = dict ( required = False , default = None , choices = [ ' yes ' , ' no ' ] , type = ' str ' ) ,
ifname = dict ( required = False , default = None , type = ' str ' ) ,
ifname = dict ( required = False , default = None , type = ' str ' ) ,
@ -1035,11 +1019,11 @@ def main():
out = ' '
out = ' '
err = ' '
err = ' '
result = { }
result = { }
result [ ' c name' ] = nmcli . c name
result [ ' c onn_ name' ] = nmcli . c onn_ name
result [ ' state ' ] = nmcli . state
result [ ' state ' ] = nmcli . state
# check for issues
# check for issues
if nmcli . c name is None :
if nmcli . c onn_ name is None :
nmcli . module . fail_json ( msg = " You haven ' t specified a name for the connection " )
nmcli . module . fail_json ( msg = " You haven ' t specified a name for the connection " )
# team-slave checks
# team-slave checks
if nmcli . type == ' team-slave ' and nmcli . master is None :
if nmcli . type == ' team-slave ' and nmcli . master is None :
@ -1054,23 +1038,23 @@ def main():
( rc , out , err ) = nmcli . down_connection ( )
( rc , out , err ) = nmcli . down_connection ( )
( rc , out , err ) = nmcli . remove_connection ( )
( rc , out , err ) = nmcli . remove_connection ( )
if rc != 0 :
if rc != 0 :
module . fail_json ( name = ( ' No Connection named %s exists ' % nmcli . c name) , msg = err , rc = rc )
module . fail_json ( name = ( ' No Connection named %s exists ' % nmcli . c onn_ name) , msg = err , rc = rc )
elif nmcli . state == ' present ' :
elif nmcli . state == ' present ' :
if nmcli . connection_exists ( ) :
if nmcli . connection_exists ( ) :
# modify connection (note: this function is check mode aware)
# modify connection (note: this function is check mode aware)
# result['Connection']=('Connection %s of Type %s is not being added' % (nmcli.c name, nmcli.type))
# result['Connection']=('Connection %s of Type %s is not being added' % (nmcli.c onn_ name, nmcli.type))
result [ ' Exists ' ] = ' Connections do exist so we are modifying them '
result [ ' Exists ' ] = ' Connections do exist so we are modifying them '
if module . check_mode :
if module . check_mode :
module . exit_json ( changed = True )
module . exit_json ( changed = True )
( rc , out , err ) = nmcli . modify_connection ( )
( rc , out , err ) = nmcli . modify_connection ( )
if not nmcli . connection_exists ( ) :
if not nmcli . connection_exists ( ) :
result [ ' Connection ' ] = ( ' Connection %s of Type %s is being added ' % ( nmcli . c name, nmcli . type ) )
result [ ' Connection ' ] = ( ' Connection %s of Type %s is being added ' % ( nmcli . c onn_ name, nmcli . type ) )
if module . check_mode :
if module . check_mode :
module . exit_json ( changed = True )
module . exit_json ( changed = True )
( rc , out , err ) = nmcli . create_connection ( )
( rc , out , err ) = nmcli . create_connection ( )
if rc is not None and rc != 0 :
if rc is not None and rc != 0 :
module . fail_json ( name = nmcli . c name, msg = err , rc = rc )
module . fail_json ( name = nmcli . c onn_ name, msg = err , rc = rc )
if rc is None :
if rc is None :
result [ ' changed ' ] = False
result [ ' changed ' ] = False