TripleO Ansible project repository. Contains playbooks for use with TripleO OpenStack deployments.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
tripleo-ansible/tripleo_ansible/ansible_plugins/tests/molecule/tripleo_os_net_config/converge.yml

68 lines
2.4 KiB

---
- name: Converge
hosts: all
become: true
tasks:
- name: create os-net-config config file
tempfile:
state: file
prefix: os-net-config
register: onc_cfg
# This is a simple test to reconfigure the loopback interface
# because it's not easy to know what nics are available on the host
# and not breaking the current network configs.
- name: write os-net-config config file
copy:
content:
network_config:
-
type: interface
name: lo
use_dhcp: false
use_dhcpv6: false
addresses:
-
ip_netmask: 127.0.0.1/8
dest: "{{ onc_cfg.path }}"
- name: Create safe os-net-config defaults for all interfaces
become: true
shell: |
set -eux
cat > {{ onc_cfg.path }} <<EOF_CAT
network_config:
EOF_CAT
for iface in $(ls /sys/class/net | grep -v -e ^lo$ -e ^vnet$); do
mac_addr_type="$(cat /sys/class/net/${iface}/addr_assign_type)"
vf_parent="/sys/class/net/${iface}/device/physfn"
if [ "$mac_addr_type" != "0" ]; then
echo "Device has generated MAC, skipping."
elif [[ -d $vf_parent ]]; then
echo "Device (${iface}) is a SR-IOV VF, skipping."
else
HAS_LINK="$(cat /sys/class/net/${iface}/carrier || echo 0)"
TRIES=10
while [ "$HAS_LINK" == "0" -a $TRIES -gt 0 ]; do
# Need to set the link up on each iteration
ip link set dev $iface up &>/dev/null
HAS_LINK="$(cat /sys/class/net/${iface}/carrier || echo 0)"
if [ "$HAS_LINK" == "1" ]; then
break
else
sleep 1
fi
TRIES=$(( TRIES - 1 ))
done
if [ "$HAS_LINK" == "1" ] ; then
cat >> {{ onc_cfg.path }} <<EOF_CAT
-
type: interface
name: $iface
use_dhcp: true
EOF_CAT
fi
fi
done
- name: apply network config
tripleo_os_net_config:
config_file: "{{ onc_cfg.path }}"
debug: true