unable to specify allowed address pairs without mac
Summary
When creating port with network
action when allowed_address_pairs
is specified, action fails,
Steps to reproduce
Execute this playbook:
---
- hosts: localhost
gather_facts: no
vars:
openstack_cloud: "YOUR_CLOUD_PROJECT"
openstack_project_ports:
- name: "test-port"
network: "test-net"
addresses:
- subnetwork_name: "test-subnet"
allowed_address_pairs:
- ip_address: "192.168.1.100"
security_groups:
- "default"
openstack_project_networks:
- name: "test-net"
subnet_name: "test-subnet"
subnet_cidr: "192.168.1.0/24"
tasks:
- include_role: { name: "openstack", tasks_from: "network" }
Expected behavior
Everything should work fine.
Actual behavior
Creating port fails.
Relevant logs and/or screenshots
...
_________________________________
< TASK [openstack : create ports] >
---------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
included: /home/bdaca/Praca/ansible-playbooks/ansible-roles/openstack/tasks/network_ports_create.yml for localhost
_____________________________________________
< TASK [openstack : geting openstack subnets] >
---------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [localhost -> localhost]
___________________________________________
< TASK [openstack : geting openstack ports] >
-------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [localhost -> localhost]
_____________________________________________________________
< TASK [openstack : check if subnetworks used in ports exist] >
-------------------------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
____________________________________________________
< TASK [openstack : check if subnetworks are unique] >
----------------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
skipping: [localhost] => (item=test-subnet)
_________________________________
< TASK [openstack : create ports] >
---------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'unicode object' has no attribute 'mac_address'\n\nThe error appears to have been in '/home/bdaca/Praca/ansible-playbooks/ansible-roles/openstack/tasks/network_ports_create.yml': line 30, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# related issue: https://github.com/ansible/ansible/issues/47182\n- name: \"create ports\"\n ^ here\n"}
Possible fixes
The problem is with this variable definition:
_openstack_port_in_openstack_ports: |
{{
openstack_ports
| selectattr('name', 'equalto', port.name)
| first
| default()
}}
When port does not exist, this variable has "\n"
value instead of being empty. Just add -
behind |
.