Task to modify an ansible host's ip-addr while connected

  • I have a router/host: mgmt_ip_addr = 1.1.1.1
  • I use ansible to connect to this router/host
  • My task is to apply a new configuration to this router.
  • This new config will modify the mgmt_ip_addr of the host to 2.2.2.2

You see the problem here? I used 1.1.1.1 to connect to this host. Now I’m planning on modifying this ip to 2.2.2.2
As soon as the new config gets applied, my ansible ssh session breaks. Makes sense, my new config modified the mgmt ip.

However, I have a bgp task that should run after the new config has been applied. Obviously this bgp task never gets run because the session is already broken.

Is there a workaround for this? I want to be able to change and mgmt ip and continue working on other tasks after that during the same playbook run.

`

---## RENDER CONFIG, AND DO CONFIG OVERRIDE  - name: "Rendering Junos jinja template into conf"
    template:
      src: "template_full_config.j2"
      dest: "/Users/mfatty/Projects/ansible/nql_ansible/roles/junos_dut_role/rendered_full_config.conf"
    tags: config_override  - name: "load override with new config"
    juniper_junos_config:
      provider: "{{ credentials }}"
      config_mode: "private"
      load: "override"
      src: "/Users/mfatty/Projects/ansible/nql_ansible/roles/junos_dut_role/rendered_full_config.conf"
      format: "text"
    register: response
    tags: config_override  - debug: msg = {{ response }}
    tags: config_override## VERIFY BGP STATE
  - name: check bgp status
    juniper_junos_command:
      provider: "{{ credentials }}"
      commands: "show bgp summary"
    tags: verify_bgp
    register: response  - debug:
      var: response.stdout_lines
    tags: verify_bgp

`

Thanks
Mo.

Hi,

Perhaps you should look around “meta: reset_connection” described here :

https://docs.ansible.com/ansible/latest/modules/meta_module.html

Little more details here :

https://www.ansible.com/blog/rebooting-network-devices-with-ansible

But I think you have another problem to manage the ip change…So you probably need to update your inventory directly in your ansible playbook or have two different objects in your inventory, so have two play in your playbook.

Regards,

JYL