Commit c7fac123 by Alain Takoudjou

Ansible VM: Configure default route to interface eth1 if it exists

1 parent 3408304d
......@@ -23,6 +23,7 @@
when: netconfig_file.stat.exists == True
ignore_errors: True
- include: network.yml
- include: hostname.yml
- include: user.yml
- include: sudo.yml
......
---
- name: Download network geteway ip
get_url: url=http://10.0.2.100/gateway dest=/etc/opt/gateway mode=666
ignore_errors: True
- name: stat /etc/opt/gateway
stat: path=/etc/opt/gateway
register: gateway_file
- name: Check default route
shell: /sbin/ip route list | grep default
register: default_route
ignore_errors: True
- name: Check interface eth1 exists
shell: /sbin/ifconfig | grep eth1 | wc -l
register: iface_eth1
- name: Delete default route to eth0
command: /sbin/ip route del default
when: gateway_file.stat.exists == True and iface_eth1.stdout == '1' and 'eth0' in default_route.stdout
- name: Set eth1 as default route
command: /sbin/ip route add default via {{ lookup('file', '/etc/opt/gateway') }} dev eth1
when: gateway_file.stat.exists == True and iface_eth1.stdout == '1' and not 'eth1' in default_route.stdout
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!