如果你需要在Ubuntu服务器上玩游戏的中途重新启动网络(在我的情况下是12.04),你不能使用service
:
# service networking restart
stop: Job failed while stopping
start: Job is already running: networking
以下内容在命令行上有效,但使用Ansible(1.8.4)时会将您锁定:
command: ifdown eth0 && ifup eth0
ifdown
取下接口,但ifup
不运行
如何重新启动界面?
解决方案是在新的shell中运行命令:
command: bash -c "ifdown eth0 && ifup eth0"
你也可以使用外壳模块:
shell: "ifdown eth0 && ifup eth0"
我建议在ifdown和ifup之间等待1秒,并独立于ifdown的退出代码运行ifup。此外,你可能不想每次运行这个易操作的剧本时都运行重置网络,所以什么时候的条件会阻止这种情况:
- name: Restart all network interfaces except loopback device
shell: "ifdown --exclude=lo -a; sleep 1; ifup --exclude=lo -a"
when: configure_lxc_bridge|changed