Skip to content
Merged
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
1 change: 1 addition & 0 deletions ansible/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
- common-osp
- controlplane
- dataplane
- post
8 changes: 8 additions & 0 deletions ansible/roles/post/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
external_net_name: public
external_net_cidr: 172.19.0.0/16
external_net_gateway: 172.19.0.1
external_net_alloc_start: 172.19.100.1
external_net_alloc_end: 172.19.254.254
external_net_physical_network: datacentre
external_network_vlan_id: 19
31 changes: 31 additions & 0 deletions ansible/roles/post/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- name: Create vlan interface on external interface
vars:
vlan_interface: "{{ iface_2 }}.{{ external_network_vlan_id }}"
shell: |
ip link add link {{ iface_2 }} name {{ vlan_interface }} type vlan id {{ external_network_vlan_id }}
ip link set dev {{ iface_2 }} up
ip link set dev {{ vlan_interface }} up
ip a a {{ external_net_gateway }}/{{ external_net_cidr.split('/')[1] }} dev {{ vlan_interface }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Line 9 assigns the gateway IP to the host VLAN interface.

This uses external_net_gateway as the interface address, which can conflict with the actual gateway and break routing. Use a dedicated host-side VLAN IP variable instead.

Suggested fix
+- name: Validate external VLAN interface addressing
+  ansible.builtin.assert:
+    that:
+      - external_net_interface_ip is defined
+      - external_net_interface_ip != external_net_gateway
+    fail_msg: "Set external_net_interface_ip to a host IP different from external_net_gateway."
+
 - name: Create vlan interface on external interface
   vars:
     vlan_interface: "{{ iface_2 }}.{{ external_network_vlan_id }}"
   shell: |
     ip link add link {{ iface_2 }} name {{ vlan_interface }} type vlan id {{ external_network_vlan_id }}
     ip link set dev {{ iface_2 }} up
     ip link set dev {{ vlan_interface }} up
-    ip a a {{ external_net_gateway }}/{{ external_net_cidr.split('/')[1] }} dev {{ vlan_interface }}
+    ip a a {{ external_net_interface_ip }}/{{ external_net_cidr.split('/')[1] }} dev {{ vlan_interface }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ansible/roles/post/tasks/main.yml` at line 9, The task is assigning the
actual gateway IP (external_net_gateway) to the host VLAN interface which can
conflict with routing; change the ip address assignment to use a dedicated
host-side VLAN IP variable (e.g. external_net_host_ip or host_vlan_ip) instead
of external_net_gateway: update the ip command that uses external_net_gateway,
external_net_cidr and vlan_interface so it adds external_net_host_ip/{{
external_net_cidr.split('/')[1] }} on {{ vlan_interface }} and ensure the new
variable is defined in inventory/vars where appropriate.

become: true
Comment on lines +2 to +10
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

VLAN interface creation is not idempotent.

The ip link add command will fail if the interface already exists. Running this role twice will result in failure. Consider checking for interface existence first.

Suggested fix for idempotency
 - name: Create vlan interface on external interface
   vars:
     vlan_interface: "{{ iface_2 }}.{{ external_network_vlan_id }}"
   shell: |
+    if ip link show {{ vlan_interface }} >/dev/null 2>&1; then
+      echo "Interface {{ vlan_interface }} already exists, skipping creation"
+    else
+      ip link add link {{ iface_2 }} name {{ vlan_interface }} type vlan id {{ external_network_vlan_id }}
+    fi
-    ip link add link {{ iface_2 }} name {{ vlan_interface }} type vlan id {{ external_network_vlan_id }}
     ip link set dev {{ iface_2 }} up
     ip link set dev {{ vlan_interface }} up
-    ip a a {{ external_net_gateway }}/{{ external_net_cidr.split('/')[1] }} dev {{ vlan_interface }}
+    ip addr replace {{ external_net_interface_ip }}/{{ external_net_cidr.split('/')[1] }} dev {{ vlan_interface }}
   become: true

Note: Using ip addr replace instead of ip addr add also improves idempotency for the IP assignment.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ansible/roles/post/tasks/main.yml` around lines 2 - 10, The VLAN creation
task ("Create vlan interface on external interface") is not idempotent because
the shell runs "ip link add" unconditionally; modify the task to first check
whether the VLAN interface (vlan_interface variable derived from iface_2 and
external_network_vlan_id) already exists and only run the add command if
missing, then always run "ip link set dev {{ iface_2 }} up" and "ip link set dev
{{ vlan_interface }} up"; also replace the IP assignment line to use "ip addr
replace" (or the equivalent) instead of "ip a a" so the address assignment is
idempotent. Use the vlan_interface variable and the same task name to locate and
update the logic.


- name: Create external network
shell: |
oc rsh -n openstack openstackclient openstack network create \
--external \
--provider-network-type vlan \
--provider-physical-network {{ external_net_physical_network }} \
--provider-segment {{ external_network_vlan_id }} \
{{ external_net_name }}

- name: Create external subnet
shell: |
oc rsh -n openstack openstackclient openstack subnet create \
--network {{ external_net_name }} \
--subnet-range {{ external_net_cidr }} \
--gateway {{ external_net_gateway }} \
--allocation-pool start={{ external_net_alloc_start }},end={{ external_net_alloc_end }} \
--no-dhcp \
{{ external_net_name }}-subnet


Loading