@ -216,112 +216,113 @@ options:
'''
'''
EXAMPLES = '''
EXAMPLES = '''
The following examples are working examples that I have run in the field . I followed follow the structure :
# These examples are using the following inventory:
` ` `
#
| _ / inventory / cloud - hosts
# ## Directory layout:
| / group_vars / openstack - stage . yml
#
| / host_vars / controller - 01. openstack . host . com
# |_/inventory/cloud-hosts
| / host_vars / controller - 02. openstack . host . com
# | /group_vars/openstack-stage.yml
| _ / playbook / library / nmcli . py
# | /host_vars/controller-01.openstack.host.com
| / playbook - add . yml
# | /host_vars/controller-02.openstack.host.com
| / playbook - del . yml
# |_/playbook/library/nmcli.py
` ` `
# | /playbook-add.yml
# | /playbook-del.yml
## inventory examples
# ```
### groups_vars
#
` ` ` yml
# ## inventory examples
- - -
# ### groups_vars
#devops_os_define_network
# ```yml
storage_gw : " 192.0.2.254 "
# ---
external_gw : " 198.51.100.254 "
# #devops_os_define_network
tenant_gw : " 203.0.113.254 "
# storage_gw: "192.0.2.254"
# external_gw: "198.51.100.254"
#Team vars
# tenant_gw: "203.0.113.254"
nmcli_team :
#
- conn_name : tenant
# #Team vars
ip4 : ' {{ tenant_ip }} '
# nmcli_team:
gw4 : ' {{ tenant_gw }} '
# - conn_name: tenant
- conn_name : external
# ip4: '{{ tenant_ip }}'
ip4 : ' {{ external_ip }} '
# gw4: '{{ tenant_gw }}'
gw4 : ' {{ external_gw }} '
# - conn_name: external
- conn_name : storage
# ip4: '{{ external_ip }}'
ip4 : ' {{ storage_ip }} '
# gw4: '{{ external_gw }}'
gw4 : ' {{ storage_gw }} '
# - conn_name: storage
nmcli_team_slave :
# ip4: '{{ storage_ip }}'
- conn_name : em1
# gw4: '{{ storage_gw }}'
ifname : em1
# nmcli_team_slave:
master : tenant
# - conn_name: em1
- conn_name : em2
# ifname: em1
ifname : em2
# master: tenant
master : tenant
# - conn_name: em2
- conn_name : p2p1
# ifname: em2
ifname : p2p1
# master: tenant
master : storage
# - conn_name: p2p1
- conn_name : p2p2
# ifname: p2p1
ifname : p2p2
# master: storage
master : external
# - conn_name: p2p2
# ifname: p2p2
#bond vars
# master: external
nmcli_bond :
#
- conn_name : tenant
# #bond vars
ip4 : ' {{ tenant_ip }} '
# nmcli_bond:
gw4 : ' '
# - conn_name: tenant
mode : balance - rr
# ip4: '{{ tenant_ip }}'
- conn_name : external
# gw4: ''
ip4 : ' {{ external_ip }} '
# mode: balance-rr
gw4 : ' '
# - conn_name: external
mode : balance - rr
# ip4: '{{ external_ip }}'
- conn_name : storage
# gw4: ''
ip4 : ' {{ storage_ip }} '
# mode: balance-rr
gw4 : ' {{ storage_gw }} '
# - conn_name: storage
mode : balance - rr
# ip4: '{{ storage_ip }}'
nmcli_bond_slave :
# gw4: '{{ storage_gw }}'
- conn_name : em1
# mode: balance-rr
ifname : em1
# nmcli_bond_slave:
master : tenant
# - conn_name: em1
- conn_name : em2
# ifname: em1
ifname : em2
# master: tenant
master : tenant
# - conn_name: em2
- conn_name : p2p1
# ifname: em2
ifname : p2p1
# master: tenant
master : storage
# - conn_name: p2p1
- conn_name : p2p2
# ifname: p2p1
ifname : p2p2
# master: storage
master : external
# - conn_name: p2p2
# ifname: p2p2
#ethernet vars
# master: external
nmcli_ethernet :
#
- conn_name : em1
# #ethernet vars
ifname : em1
# nmcli_ethernet:
ip4 : ' {{ tenant_ip }} '
# - conn_name: em1
gw4 : ' {{ tenant_gw }} '
# ifname: em1
- conn_name : em2
# ip4: '{{ tenant_ip }}'
ifname : em2
# gw4: '{{ tenant_gw }}'
ip4 : ' {{ tenant_ip1 }} '
# - conn_name: em2
gw4 : ' {{ tenant_gw }} '
# ifname: em2
- conn_name : p2p1
# ip4: '{{ tenant_ip1 }}'
ifname : p2p1
# gw4: '{{ tenant_gw }}'
ip4 : ' {{ storage_ip }} '
# - conn_name: p2p1
gw4 : ' {{ storage_gw }} '
# ifname: p2p1
- conn_name : p2p2
# ip4: '{{ storage_ip }}'
ifname : p2p2
# gw4: '{{ storage_gw }}'
ip4 : ' {{ external_ip }} '
# - conn_name: p2p2
gw4 : ' {{ external_gw }} '
# ifname: p2p2
` ` `
# ip4: '{{ external_ip }}'
# gw4: '{{ external_gw }}'
### host_vars
# ```
` ` ` yml
#
- - -
# ### host_vars
storage_ip : " 192.0.2.91/23 "
# ```yml
external_ip : " 198.51.100.23/21 "
# ---
tenant_ip : " 203.0.113.77/23 "
# storage_ip: "192.0.2.91/23"
` ` `
# external_ip: "198.51.100.23/21"
# tenant_ip: "203.0.113.77/23"
# ```
## playbook-add.yml example
## playbook-add.yml example
` ` ` yml
- - -
- - -
- hosts : openstack - stage
- hosts : openstack - stage
remote_user : root
remote_user : root
@ -360,42 +361,40 @@ tenant_ip: "203.0.113.77/23"
- ' {{ nmcli_team_slave }} '
- ' {{ nmcli_team_slave }} '
###### Working with all cloud nodes - Bonding
###### Working with all cloud nodes - Bonding
# - name: try nmcli add bond - conn_name only & ip4 gw4 mode
- name : try nmcli add bond - conn_name only & ip4 gw4 mode
# nmcli:
nmcli :
# type: bond
type : bond
# conn_name: '{{ item.conn_name }}'
conn_name : ' {{ item.conn_name }} '
# ip4: '{{ item.ip4 }}'
ip4 : ' {{ item.ip4 }} '
# gw4: '{{ item.gw4 }}'
gw4 : ' {{ item.gw4 }} '
# mode: '{{ item.mode }}'
mode : ' {{ item.mode }} '
# state: present
state : present
# with_items:
with_items :
# - '{{ nmcli_bond }}'
- ' {{ nmcli_bond }} '
#
# - name: try nmcli add bond- slave
- name : try nmcli add bond - slave
# nmcli:
nmcli :
# type: bond-slave
type : bond - slave
# conn_name: '{{ item.conn_name }}'
conn_name : ' {{ item.conn_name }} '
# ifname: '{{ item.ifname }}'
ifname : ' {{ item.ifname }} '
# master: '{{ item.master }}'
master : ' {{ item.master }} '
# state: present
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 - conn_name only & ip4 gw4
- name : nmcli add Ethernet - conn_name only & ip4 gw4
# nmcli:
nmcli :
# type: ethernet
type : ethernet
# conn_name: '{{ item.conn_name }}'
conn_name : ' {{ item.conn_name }} '
# ip4: '{{ item.ip4 }}'
ip4 : ' {{ item.ip4 }} '
# gw4: '{{ item.gw4 }}'
gw4 : ' {{ item.gw4 }} '
# state: present
state : present
# with_items:
with_items :
# - '{{ nmcli_ethernet }}'
- ' {{ nmcli_ethernet }} '
` ` `
## playbook-del.yml example
## playbook-del.yml example
` ` ` yml
- - -
- - -
- hosts : openstack - stage
- hosts : openstack - stage
remote_user : root
remote_user : root
@ -421,7 +420,7 @@ tenant_ip: "203.0.113.77/23"
- conn_name : team - p1p2
- conn_name : team - p1p2
- conn_name : team - p2p1
- conn_name : team - p2p1
- conn_name : 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 :
- nmcli :
conn_name : my - eth1
conn_name : my - eth1
@ -464,7 +463,7 @@ tenant_ip: "203.0.113.77/23"
- nmcli :
- nmcli :
ctype : ethernet
ctype : ethernet
name : my - eth1
name : my - eth1
ifname : *
ifname : ' * '
state : present
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:
@ -474,20 +473,20 @@ tenant_ip: "203.0.113.77/23"
type : ethernet
type : ethernet
state : present
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
returned if an error occurs .
# returned if an error occurs .
- 0 Success - indicates the operation succeeded
# - 0 Success - indicates the operation succeeded
- 1 Unknown or unspecified error
# - 1 Unknown or unspecified error
- 2 Invalid user input , wrong nmcli invocation
# - 2 Invalid user input, wrong nmcli invocation
- 3 Timeout expired ( see - - wait option )
# - 3 Timeout expired (see --wait option )
- 4 Connection activation failed
# - 4 Connection activation failed
- 5 Connection deactivation failed
# - 5 Connection deactivation failed
- 6 Disconnecting device failed
# - 6 Disconnecting device failed
- 7 Connection deletion failed
# - 7 Connection deletion failed
- 8 NetworkManager is not running
# - 8 NetworkManager is not running
- 9 nmcli and NetworkManager versions mismatch
# - 9 nmcli and NetworkManager versions mismatch
- 10 Connection , device , or access point does not exist .
# - 10 Connection, device, or access point does not exist .
'''
'''
# import ansible.module_utils.basic
# import ansible.module_utils.basic
import os
import os