Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save inceabdullah/3ac7632b7ccecdd28c725ec4e7070c7f to your computer and use it in GitHub Desktop.
Save inceabdullah/3ac7632b7ccecdd28c725ec4e7070c7f to your computer and use it in GitHub Desktop.
Ansible Set Default Route with Connecting IPv4

Ansible Set Default Route with Connecting IPv4

- name: set default route with connecting ipv4
  hosts: nodes
  tasks:
   - name: make default gw
     command: sudo bash -c "export IP={{ IP }}; ip r | grep $IP |grep -Po 'dev \K\S+' |xargs -I{} bash -c \"DEV={};GW=`echo '${IP%.*}.1'`;ip r r default via \${GW} dev \${DEV}; ip r\""
     vars:
       IP: "{{ ansible_facts['env'].SSH_CONNECTION.split(' ')[2] }}"
     register: output
   - name: debug
     debug:
       msg: "{{ output }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment