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

16 views
Skip to first unread message

Momodou Fatty

unread,
Jul 1, 2020, 3:53:59 AM7/1/20
to Ansible Project
 - 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. 

Jean-Yves LENHOF

unread,
Jul 1, 2020, 4:48:30 AM7/1/20
to ansible...@googlegroups.com

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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/77463894-dd66-43ca-800e-2f0f36276725o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages