Updated as per bcoca's comments:

removed 'default' in state:
removed defunct action:
removed reference to load_platform_subclass
changed cname to conn_name
This commit is contained in:
Chris Long 2015-05-15 00:45:51 +10:00 committed by Greg DeKoenigsberg
parent 3b44082dd6
commit 2856116162

View file

@ -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: cname 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 cname) of bridge, team, bond master connection profile. - master <master (ifname, or connection UUID or conn_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:
- {cname: 'tenant', ip4: "{{tenant_ip}}", gw4: "{{tenant_gw}}"} - {conn_name: 'tenant', ip4: "{{tenant_ip}}", gw4: "{{tenant_gw}}"}
- {cname: 'external', ip4: "{{external_ip}}", gw4: "{{external_gw}}"} - {conn_name: 'external', ip4: "{{external_ip}}", gw4: "{{external_gw}}"}
- {cname: 'storage', ip4: "{{storage_ip}}", gw4: "{{storage_gw}}"} - {conn_name: 'storage', ip4: "{{storage_ip}}", gw4: "{{storage_gw}}"}
nmcli_team_slave: nmcli_team_slave:
- {cname: 'em1', ifname: 'em1', master: 'tenant'} - {conn_name: 'em1', ifname: 'em1', master: 'tenant'}
- {cname: 'em2', ifname: 'em2', master: 'tenant'} - {conn_name: 'em2', ifname: 'em2', master: 'tenant'}
- {cname: 'p2p1', ifname: 'p2p1', master: 'storage'} - {conn_name: 'p2p1', ifname: 'p2p1', master: 'storage'}
- {cname: 'p2p2', ifname: 'p2p2', master: 'external'} - {conn_name: 'p2p2', ifname: 'p2p2', master: 'external'}
#bond vars #bond vars
nmcli_bond: nmcli_bond:
- {cname: 'tenant', ip4: "{{tenant_ip}}", gw4: '', mode: 'balance-rr'} - {conn_name: 'tenant', ip4: "{{tenant_ip}}", gw4: '', mode: 'balance-rr'}
- {cname: 'external', ip4: "{{external_ip}}", gw4: '', mode: 'balance-rr'} - {conn_name: 'external', ip4: "{{external_ip}}", gw4: '', mode: 'balance-rr'}
- {cname: 'storage', ip4: "{{storage_ip}}", gw4: "{{storage_gw}}", mode: 'balance-rr'} - {conn_name: 'storage', ip4: "{{storage_ip}}", gw4: "{{storage_gw}}", mode: 'balance-rr'}
nmcli_bond_slave: nmcli_bond_slave:
- {cname: 'em1', ifname: 'em1', master: 'tenant'} - {conn_name: 'em1', ifname: 'em1', master: 'tenant'}
- {cname: 'em2', ifname: 'em2', master: 'tenant'} - {conn_name: 'em2', ifname: 'em2', master: 'tenant'}
- {cname: 'p2p1', ifname: 'p2p1', master: 'storage'} - {conn_name: 'p2p1', ifname: 'p2p1', master: 'storage'}
- {cname: 'p2p2', ifname: 'p2p2', master: 'external'} - {conn_name: 'p2p2', ifname: 'p2p2', master: 'external'}
#ethernet vars #ethernet vars
nmcli_ethernet: nmcli_ethernet:
- {cname: 'em1', ifname: 'em1', ip4: "{{tenant_ip}}", gw4: "{{tenant_gw}}"} - {conn_name: 'em1', ifname: 'em1', ip4: "{{tenant_ip}}", gw4: "{{tenant_gw}}"}
- {cname: 'em2', ifname: 'em2', ip4: "{{tenant_ip1}}", gw4: "{{tenant_gw}}"} - {conn_name: 'em2', ifname: 'em2', ip4: "{{tenant_ip1}}", gw4: "{{tenant_gw}}"}
- {cname: 'p2p1', ifname: 'p2p1', ip4: "{{storage_ip}}", gw4: "{{storage_gw}}"} - {conn_name: 'p2p1', ifname: 'p2p1', ip4: "{{storage_ip}}", gw4: "{{storage_gw}}"}
- {cname: 'p2p2', ifname: 'p2p2', ip4: "{{external_ip}}", gw4: "{{external_gw}}"} - {conn_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 - cname only & ip4 gw4 - name: try nmcli add team - conn_name only & ip4 gw4
nmcli: type=team cname={{item.cname}} ip4={{item.ip4}} gw4={{item.gw4}} state=present nmcli: type=team conn_name={{item.conn_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 cname={{item.cname}} ifname={{item.ifname}} master={{item.master}} state=present nmcli: type=team-slave conn_name={{item.conn_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 - cname only & ip4 gw4 mode # - name: try nmcli add bond - conn_name only & ip4 gw4 mode
# nmcli: type=bond cname={{item.cname}} ip4={{item.ip4}} gw4={{item.gw4}} mode={{item.mode}} state=present # nmcli: type=bond conn_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 cname={{item.cname}} ifname={{item.ifname}} master={{item.master}} state=present # nmcli: type=bond-slave conn_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 - cname only & ip4 gw4 # - name: nmcli add Ethernet - conn_name only & ip4 gw4
# nmcli: type=ethernet cname={{item.cname}} ip4={{item.ip4}} gw4={{item.gw4}} state=present # nmcli: type=ethernet conn_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: cname={{item.cname}} state=absent nmcli: conn_name={{item.conn_name}} state=absent
with_items: with_items:
- { cname: 'em1'} - { conn_name: 'em1'}
- { cname: 'em2'} - { conn_name: 'em2'}
- { cname: 'p1p1'} - { conn_name: 'p1p1'}
- { cname: 'p1p2'} - { conn_name: 'p1p2'}
- { cname: 'p2p1'} - { conn_name: 'p2p1'}
- { cname: 'p2p2'} - { conn_name: 'p2p2'}
- { cname: 'tenant'} - { conn_name: 'tenant'}
- { cname: 'storage'} - { conn_name: 'storage'}
- { cname: 'external'} - { conn_name: 'external'}
- { cname: 'team-em1'} - { conn_name: 'team-em1'}
- { cname: 'team-em2'} - { conn_name: 'team-em2'}
- { cname: 'team-p1p1'} - { conn_name: 'team-p1p1'}
- { cname: 'team-p1p2'} - { conn_name: 'team-p1p2'}
- { cname: 'team-p2p1'} - { conn_name: 'team-p2p1'}
- { cname: 'team-p2p2'} - { conn_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: cname=my-eth1 ifname=eth1 type=ethernet ip4=192.168.100.100/24 gw4=192.168.100.1 state=present - nmcli: conn_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: cname=my-team1 ifname=my-team1 type=team ip4=192.168.100.100/24 gw4=192.168.100.1 state=present enabled=yes - nmcli: conn_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: cname=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: conn_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: cname=my-eth1 dns4=["8.8.8.8", "8.8.4.4"] state=present -nmcli: conn_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: cname=my-eth1 mtu=9000 state=present - nmcli: conn_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.cname==con_item: if self.conn_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.cname) cmd.append(self.conn_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.cname) cmd.append(self.conn_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.cname is not None: if self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_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.cname is not None: elif self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_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.cname) cmd.append(self.conn_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.cname is not None: if self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_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.cname is not None: elif self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_name)
cmd.append('master') cmd.append('master')
if self.cname is not None: if self.conn_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.cname) cmd.append(self.conn_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.cname is not None: if self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_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.cname is not None: elif self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_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.cname) cmd.append(self.conn_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.cname is not None: if self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_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.cname is not None: elif self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_name)
cmd.append('master') cmd.append('master')
if self.cname is not None: if self.conn_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.cname) cmd.append(self.conn_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 cname=my-eth1 ifname=eth1 type=ethernet ip4=192.168.100.100/24 gw4=192.168.100.1 state=present # - nmcli: name=add conn_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.cname is not None: if self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_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.cname is not None: elif self.conn_name is not None:
cmd.append(self.cname) cmd.append(self.conn_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 cname=my-eth1 ifname=eth1 type=ethernet ip4=192.168.100.100/24 gw4=192.168.100.1 state=present # - nmcli: name=add conn_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.cname) cmd.append(self.conn_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.cname) cmd.append(self.conn_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['cname']=nmcli.cname result['conn_name']=nmcli.conn_name
result['state']=nmcli.state result['state']=nmcli.state
# check for issues # check for issues
if nmcli.cname is None: if nmcli.conn_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.cname), msg=err, rc=rc) module.fail_json(name =('No Connection named %s exists' % nmcli.conn_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.cname, nmcli.type)) # result['Connection']=('Connection %s of Type %s is not being added' % (nmcli.conn_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.cname, nmcli.type)) result['Connection']=('Connection %s of Type %s is being added' % (nmcli.conn_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.cname, msg=err, rc=rc) module.fail_json(name=nmcli.conn_name, msg=err, rc=rc)
if rc is None: if rc is None:
result['changed']=False result['changed']=False