1

I have been trying to call the 'restart the network' service in a fire and forget mode because obviously I will get disconnected from the SSH connection after I restart the network in a VM so I wanted to have a timeout process to do that.

In order to do that I did this inside of my restart networking tasks:

- name: Restart network
  become: true
  service: name=network state=restarted
  async: 1000
  poll: 0

When Ansible gets to this point I get this error:

fatal: [build]: FAILED! => {"failed": true, "msg": "async mode is not supported with the service module"}

Which I found that is an Ansible bug that is not yet in production and they still have it in the development branch, which I don't want to do because that would also mean more possible bugs in Ansible.

So, I have two options in my opinion, either I wait for the new release of Ansible to come with the bug fix or change async: 0 and poll: 0 to wait for the service to finish ( which it will never is going to finish ) so I press CTRL+C when get to that point to stop the service manually.

I don't want to go either of those routes because they are not very efficient for me, so I was wondering if there is a solution would be better at this point.

VaTo
  • 2,936
  • 7
  • 38
  • 77

1 Answers1

2

Try this as a temporary workaround:

- name: Restart network
  become: yes
  shell: sleep 2 && service network restart
  async: 1
  poll: 0

And don't forget to wait_for port 22 after this task to avoid host unreachable error.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • how can I add the `wait_for`? – VaTo Mar 24 '17 at 19:44
  • Something like this? http://pastebin.centos.org/74291/85097149/ I mean, can I add the wait_for in the same file? – VaTo Mar 24 '17 at 19:52
  • I was wondering why localhost? In this case I'm trying to restart the network in a remote server, wouldn't that has to have the ip of the server? – VaTo Mar 24 '17 at 20:28
  • As I saw in that answer the person is waiting to connect to the server's ip by specifying the ip, in my case I don't know the IP because it will depend on the ip that is given by the dhcp server. – VaTo Mar 24 '17 at 20:34
  • If you don't need to execute any further tasks after network restart, you can omit wait_for and just complete the play. If you do need to do something else on that server after network restart, you should find the way to wait for it to come back online: most common way to do this is a wait_for module, but you run it (delegate) on localhost (control machine), because otherwise ansible will try to execute it on remote host that is in a process of network restart and will fail. – Konstantin Suvorov Mar 25 '17 at 05:08