Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
exclude_paths:
- ./tests/requirements
- .github

warn_list:
- experimental # all rules tagged as experimental
- fqcn-builtins # Use FQCN for builtin actions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ The configuration is persisted within `/etc/network/{if-up.d|if-down.d}`.

Use `state: absent` to remove a specific route. Routes are identified by the `network`.

In some setups it may be required to override the interface_name the script is listinging to (e.g. proxmox lxc container):

ip_route_configs:
eth0:
- gateway: 172.0.1.1
network: 172.0.1.0/24
interface_name: --all

## Tags

Tags can be used to limit the role execution to a particular task module. Following tags are available:
Expand Down
2 changes: 1 addition & 1 deletion tasks/device.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
interface: "{{ interfaces | selectattr('name', 'equalto', ip_route_config.key) | first }}"

- name: Configure routes
include: route/main.yml
include_tasks: route/main.yml
with_items: "{{ ip_route_config.value }}"
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
changed_when: no

- name: Configure routes for devices
include: device.yml
include_tasks: device.yml
loop_control:
loop_var: ip_route_config
with_dict: "{{ ip_route_configs }}"
4 changes: 2 additions & 2 deletions tasks/route/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
route_if_down_script: "/etc/network/if-down.d/{{ interface.name | regex_replace('\\.', '-') }}-{{ route_id }}"

- name: Create route
include: create.yml
include_tasks: create.yml
when: route_state == 'present'

- name: Delete route
include: delete.yml
include_tasks: delete.yml
when: route_state != 'present'
2 changes: 1 addition & 1 deletion templates/if-down.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

{{ ansible_managed|comment }}

if [ "$IFACE" = "{{ interface.name }}" ]; then
if [ "$IFACE" = "{{ item.interface_name | default(interface.name) }}" ]; then
ip route del {{ item.network }}
fi
2 changes: 1 addition & 1 deletion templates/if-up.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

{{ ansible_managed|comment }}

if [ "$IFACE" = "{{ interface.name }}" ]; then
if [ "$IFACE" = "{{ item.interface_name | default(interface.name) }}" ]; then
ip route add {{ item.network }} via {{ item.gateway }} dev {{ interface.device }} proto kernel src {{ interface.ipv4.address }}
fi