# Restart network interfaces

**URL:** <https://forum.ansible.com/t/restart-network-interfaces/21363>\
**Category:** Ansible Project\
**Created:** [May 5, 2016, 1:52pm UTC](https://forum.ansible.com/t/restart-network-interfaces/21363 "2016-05-05T13:52:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carl\_Wainwright](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Carl\_Wainwright](https://forum.ansible.com/u/Carl_Wainwright)\
**Post date:** [May 5, 2016, 1:52pm UTC](https://forum.ansible.com/t/restart-network-interfaces/21363/1 "2016-05-05T13:52:22Z")

</div>

Hello,

I am using Ansible to update templated VM machines with correct networking. My inventory contains the templated hosts [nos5] and the deployed host [nos6]. It should be noted that the interface I am changing is the one I’m using in Ansible .

The Ansible playbook successfully updates the ifcfg-eth0 file and restarts the network. However, it hangs for about 1-2 minutes before returning a failure code.

> fatal: [nos5]: FAILED! =\> {“changed”: false, “failed”: true, “invocation”: {“module\_name”: “command”}, “module\_stderr”: “”, “module\_stdout”: “\r\n”, “msg”: “MODULE FAILURE”, “parsed”: false}

The tasks I’m executing are as follows.

> - name: Update Networking for NOS  
> lineinfile:  
> dest: /etc/sysconfig/network-scripts/ifcfg-eth0  
> regexp: “^IPADDR”  
> line: “IPADDR=10.157.{{ VDC\_Number }}.100”  
> when: target\_vm == “NOS”  
> register: network\_nos\_ok
> 
> - name: Bounce the interface  
> shell: ifdown eth0; ifup eth0  
> when: target\_vm == “NOS” and network\_nos\_ok is defined

The starting IP is 10.157.5.100, and the changed IP is 10.157.6.100.

Is there a way to make this happen without the excessive delaty and report success?

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [May 5, 2016, 3:31pm UTC](https://forum.ansible.com/t/restart-network-interfaces/21363/2 "2016-05-05T15:31:36Z")

</div>

Have a look at [async/poll](http://docs.ansible.com/ansible/playbooks_async.html). This isn’t what it was designed for, but it will likely solve your issue… You’ll probably want to do a sleep 5 && in front of the ifdown/ifup just to make sure that the async daemonization has occurred and returned the jid to Ansible before bouncing the interface (if it happens too quickly, you’ll see the same issue).

I’d suggest an initial async value of 30 and poll 10. It’ll be a little slower than it probably needs to be, but should be very safe from any races that way.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [May 5, 2016, 5:44pm UTC](https://forum.ansible.com/t/restart-network-interfaces/21363/3 "2016-05-05T17:44:47Z")

</div>

Maybe you can get some tricks from here:  
[https://dmsimard.com/2016/03/15/changing-the-ssh-port-with-ansible](https://dmsimard.com/2016/03/15/changing-the-ssh-port-with-ansible)

This is about changing the ssh port via ansible, but the problem is  
similar (changing port vs. changing IP adress).

Johannes
