Ansible:在Ubuntu上重新启动网络 如果您需要在Ubuntu服务器(在我的情况下为12.04)的游戏中间重新启动网络,则不能使用服务< /代码>: # service networking restart stop: Job failed while stopping start: Job is already running: networking

Ansible:在Ubuntu上重新启动网络 如果您需要在Ubuntu服务器(在我的情况下为12.04)的游戏中间重新启动网络,则不能使用服务< /代码>: # service networking restart stop: Job failed while stopping start: Job is already running: networking,ubuntu,networking,ubuntu-12.04,ansible,Ubuntu,Networking,Ubuntu 12.04,Ansible,以下命令行可以使用,但Ansible(1.8.4)会将您锁定在外: command: ifdown eth0 && ifup eth0 ifdown关闭界面,但ifup不运行 如何重新启动界面?解决方案是在新shell中运行命令: command: bash -c "ifdown eth0 && ifup eth0" 您还可以使用shell模块: shell: "ifdown eth0 && ifup eth0" 我建议在ifdown和ifu

以下命令行可以使用,但Ansible(1.8.4)会将您锁定在外:

command: ifdown eth0 && ifup eth0
ifdown
关闭界面,但
ifup
不运行


如何重新启动界面?

解决方案是在新shell中运行命令:

command: bash -c "ifdown eth0 && ifup eth0"
您还可以使用shell模块:

shell: "ifdown eth0 && ifup eth0"

我建议在ifdown和ifup之间等待1秒,然后独立于ifdown的退出代码运行ifup。此外,您可能不希望每次运行此ansible playbook时都运行“重置网络”,因此“何时”条件将阻止此操作:

- name: Restart all network interfaces except loopback device
  shell: "ifdown --exclude=lo -a; sleep 1; ifup --exclude=lo -a"
  when: configure_lxc_bridge|changed

为什么?在我看来,这似乎完全符合主题。为什么投票被否决而并没有任何评论可以说明原因呢?有一些评论,抱怨这会偏离主题。评论被删除了,但没有否决票……谢谢,只是想知道我能做得更好:)为什么不能使用
shell
?可以,但建议使用
命令而不是
shell
。我已经用shell模块版本更新了我的答案,以供参考。