If you need to restart the networking in the middle of a play on an Ubuntu server (12.04 in my case) you can't use service
:
# service networking restart
stop: Job failed while stopping
start: Job is already running: networking
The following works on the command line, but with Ansible (1.8.4) it locks you out:
command: ifdown eth0 && ifup eth0
ifdown
takes down the interface, but ifup
doesn't run
How to restart the interface?
Use systemctl restart ansible-tower to restart services on clustered environments instead. Also you must restart each cluster node for certain changes to persist as opposed to a single node for a localhost install.
The solution is to run the command in a new shell:
command: bash -c "ifdown eth0 && ifup eth0"
You can also use the shell module:
shell: "ifdown eth0 && ifup eth0"
I would recommend to wait 1 sec between ifdown and ifup and run ifup independent of exit code from ifdown. Also you probably not want run reset network everytime you run this ansible playbook, so a when condition will prevent this:
- name: Restart all network interfaces except loopback device
shell: "ifdown --exclude=lo -a; sleep 1; ifup --exclude=lo -a"
when: configure_lxc_bridge|changed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With