Restart network interfaces

91 views
Skip to first unread message

Carl Wainwright

unread,
May 5, 2016, 10:44:07 AM5/5/16
to Ansible Project
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?

Matt Davis

unread,
May 5, 2016, 11:31:36 AM5/5/16
to Ansible Project
Have a look at async/poll. 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.

Johannes Kastl

unread,
May 5, 2016, 1:44:56 PM5/5/16
to ansible...@googlegroups.com
On 05.05.16 15:52 Carl Wainwright wrote:

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

Maybe you can get some tricks from here:
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

signature.asc
Reply all
Reply to author
Forward
0 new messages