diff --git a/.github/workflows/ansible-test.yaml b/.github/workflows/ansible-test.yaml index 3612b3b..51b8449 100644 --- a/.github/workflows/ansible-test.yaml +++ b/.github/workflows/ansible-test.yaml @@ -32,7 +32,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest + pip install flake8==4.0.0 pytest==6.2.4 if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Install kernel extra modules run: sudo apt-get install -y linux-modules-extra-$(uname -r) diff --git a/ansible_collections/amarao/ip/galaxy.yml b/ansible_collections/amarao/ip/galaxy.yml index 5366aa0..10e723e 100644 --- a/ansible_collections/amarao/ip/galaxy.yml +++ b/ansible_collections/amarao/ip/galaxy.yml @@ -3,7 +3,7 @@ namespace: amarao name: ip -version: 0.1.10 +version: 0.1.11 readme: README.md diff --git a/ansible_collections/amarao/ip/plugins/modules/ip_address.py b/ansible_collections/amarao/ip/plugins/modules/ip_address.py index be78193..79a1d01 100644 --- a/ansible_collections/amarao/ip/plugins/modules/ip_address.py +++ b/ansible_collections/amarao/ip/plugins/modules/ip_address.py @@ -21,7 +21,7 @@ DOCUMENTATION = """ --- module: ip_address -version_added: "2.10" +version_added: "0.0.1" author: "George Shuklin (@amarao)" short_description: Create or delete IP addresses on interfaces requirements: [iproute2] diff --git a/ansible_collections/amarao/ip/plugins/modules/ip_link_device.py b/ansible_collections/amarao/ip/plugins/modules/ip_link_device.py index 4341a9a..05de823 100644 --- a/ansible_collections/amarao/ip/plugins/modules/ip_link_device.py +++ b/ansible_collections/amarao/ip/plugins/modules/ip_link_device.py @@ -20,7 +20,7 @@ DOCUMENTATION = """ --- module: ip_link_device -version_added: "2.10" +version_added: "0.0.1" author: "George Shuklin (@amarao)" short_description: Create or delete network interfaces in Linux requirements: [iproute2] @@ -81,7 +81,7 @@ type: type: str - choices: [bridge, dummy, gre, gretap, veth, vlan, vxlan, bond] + choices: [bridge, dummy, gre, gretap, veth, vlan, vxlan, bond, vrf] description: - Type of a new interface to add or delete. - Can be specified instead of I(name) or I(group_id) @@ -1156,6 +1156,19 @@ system defaults to using the masters' mac address as actors' system address. - Valid only for I(mode)=C(802.3ad). + + vrf_options: + type: dict + description: + - Options, specific for I(type)=C(vrf) + - Should not be used for any other type. + - VRF documentation is available at https://docs.kernel.org/networking/vrf.html + + suboptions: + table: + type: str + description: + - ID of the routing table used for VRF. notes: - The module does not check the interface type when checking if interface is present or not. I(type) and corresponding options are @@ -1226,11 +1239,24 @@ bond_options: mode: 802.3ad lacp_rate: fast + - name: Add device to bond ip_link_device_attribute: # it's a different module! name: eth3 master: bond +- name: Create vrf + ip_link_device: + device: blue + type: vrf + state: present + vrf_options: + table: 42 + +- name: Enslave vxlan + ip_link_device_attribute: # it's a different module! + device: vxlan.42 + master: blue """ RETURN = """ @@ -1414,6 +1440,9 @@ "ad_user_port_key": lambda val: ['ad_user_port_key', str(val)], "ad_actor_sys_prio": lambda val: ['ad_actor_sys_prio', str(val)], "ad_actor_system": lambda addr: ['ad_actor_system', str(addr)], + }, + 'vrf': { + "table": lambda table_id: ['table', str(table_id)], } } @@ -1589,7 +1618,8 @@ def main(): 'state': {'choices': ['present', 'absent'], 'required': True}, 'type': {'choices': [ 'veth', 'vlan', 'vxlan', 'gre', - 'gretap', 'dummy', 'bridge', 'bond' + 'gretap', 'dummy', 'bridge', 'bond', + 'vrf' ]}, 'link': {}, 'txqueuelen': {'type': 'int'}, @@ -1608,6 +1638,7 @@ def main(): 'gretap_options': {'type': 'dict'}, 'bridge_options': {'type': 'dict'}, 'bond_options': {'type': 'dict'}, + 'vrf_options': {'type': 'dict'}, }, supports_check_mode=True, mutually_exclusive=[ @@ -1616,7 +1647,7 @@ def main(): [ 'vlan_options', 'vxlan_options', 'gre_options', 'gretap_options', 'veth_options', 'bridge_options', - 'bond_options' + 'bond_options', 'vrf_options' ] ], required_one_of=[['name', 'group_id']], diff --git a/ansible_collections/amarao/ip/plugins/modules/ip_link_device_attribute.py b/ansible_collections/amarao/ip/plugins/modules/ip_link_device_attribute.py index c65b780..48512bf 100644 --- a/ansible_collections/amarao/ip/plugins/modules/ip_link_device_attribute.py +++ b/ansible_collections/amarao/ip/plugins/modules/ip_link_device_attribute.py @@ -24,7 +24,7 @@ DOCUMENTATION = """ --- module: ip_link_device_attribute -version_added: "2.10" +version_added: "0.0.1" author: "George Shuklin (@amarao)" short_description: Set link-level properties for network interfaces for Linux requirements: [iproute2] diff --git a/ansible_collections/amarao/ip/tests/integration/targets/ip_link_device/tasks/main.yaml b/ansible_collections/amarao/ip/tests/integration/targets/ip_link_device/tasks/main.yaml index 6e73ad5..be94b44 100644 --- a/ansible_collections/amarao/ip/tests/integration/targets/ip_link_device/tasks/main.yaml +++ b/ansible_collections/amarao/ip/tests/integration/targets/ip_link_device/tasks/main.yaml @@ -531,3 +531,29 @@ - 'ip link del veth42' - 'ip link del bond42' failed_when: false + + +# TEST10 created vrf interface +- name: TEST10 - vrf creation + tags: [test10] + become: true + block: + - name: TEST10, create vrf + ip_link_device: + device: vrf-blue + type: vrf + state: present + vrf_options: + table: 42 + - name: TEST10, get results + command: ip -d link show dev vrf-blue + register: ip_output + - name: TEST9, check results + assert: + that: + - "'vrf-blue' in ip_output.stdout" + - "'table 42' in ip_output.stdout" + always: + - name: TEST10, cleanup + command: ip link del vrf-blue + failed_when: false