jon*_*tan 7 ubuntu networking ubuntu-12.04 ansible
如果你需要在Ubuntu服务器(在我的情况下为12.04)的游戏过程中重新启动网络,你不能使用service:
# service networking restart
stop: Job failed while stopping
start: Job is already running: networking
Run Code Online (Sandbox Code Playgroud)
以下适用于命令行,但使用Ansible(1.8.4)它会将您锁定:
command: ifdown eth0 && ifup eth0
Run Code Online (Sandbox Code Playgroud)
ifdown取下界面,但ifup不运行
如何重启界面?
解决方案是在新shell中运行该命令:
command: bash -c "ifdown eth0 && ifup eth0"
Run Code Online (Sandbox Code Playgroud)
您还可以使用shell模块:
shell: "ifdown eth0 && ifup eth0"
Run Code Online (Sandbox Code Playgroud)
我建议在 ifdown 和 ifup 之间等待 1 秒,并独立于 ifdown 的退出代码运行 ifup。此外,您可能不希望每次运行此 ansible playbook 时都运行 reset network,因此 when 条件将阻止这种情况:
- name: Restart all network interfaces except loopback device
shell: "ifdown --exclude=lo -a; sleep 1; ifup --exclude=lo -a"
when: configure_lxc_bridge|changed
Run Code Online (Sandbox Code Playgroud)