ansibleopenstackportsopenstack-neutron

Create Neutron port using Ansible and Openstack Packstack


I am trying to reproduce this Openstack command in Ansible:

neutron port-create --fixed-ip ip_address=10.180.157.136 --allowed-address-pair ip_address=10.180.157.128/27 --name port1 --security-group sg_default nw1

I have tried this task for creating this Openstack command:

  - name: Create Neutron port
    os_port:
       state: present
       fixed_ips: 10.180.157.136
       allowed_address_pairs: 10.180.157.128/27
       name: port1
       security_groups: sg_default
       network: nw1
    tags: ports

If I am running the Openstack command, works perfectly. If I am trying to run this particular task, it fails with the following error:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error updating port 7ab0ebdc-e28b-4eae-bbc9-0c00ca4cb1fd"}

And in verbose mode:

The full traceback is:
  File "/tmp/ansible_TnJOrd/ansible_module_os_port.py", line 344, in main
    port = cloud.create_port(network_id, **port_kwargs)
  File "<string>", line 2, in create_port
  File "/usr/lib/python2.7/site-packages/openstack/cloud/_utils.py", line 374, in func_wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/openstack/cloud/openstackcloud.py", line 7964, in create_port
    network_id))
  File "/usr/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 310, in post
    return self.request(url, 'POST', **kwargs)
  File "/usr/lib/python2.7/site-packages/openstack/_adapter.py", line 164, in request
    return _json_response(response, error_message=error_message)
  File "/usr/lib/python2.7/site-packages/openstack/_adapter.py", line 95, in _json_response
    exceptions.raise_from_response(response, error_message=error_message)
  File "/usr/lib/python2.7/site-packages/openstack/exceptions.py", line 205, in raise_from_response
    http_status=http_status, request_id=request_id

fatal: [localhost]: FAILED! => {
    "changed": false, 
    "invocation": {
        "module_args": {
            "admin_state_up": null, 
            "allowed_address_pairs": [
                {
                    "ip_address": "10.180.157.128/27"
                }
            ], 
            "api_timeout": null, 
            "auth": null, 
            "auth_type": null, 
            "availability_zone": null, 
            "cacert": null, 
            "cert": null, 
            "device_id": null, 
            "device_owner": null, 
            "extra_dhcp_opts": null, 
            "fixed_ips": [
                "10.180.157.136"
            ], 
            "interface": "public", 
            "key": null, 
            "mac_address": null, 
            "name": "port1", 
            "network": "nw1", 
            "no_security_groups": false, 
            "region_name": null, 
            "security_groups": [
                "36e7eb86-a2ae-48d5-8255-a4da0cdea11e"
            ], 
            "state": "present", 
            "timeout": 180, 
            "verify": null, 
            "wait": true
        }
    }, 
    "msg": "Error creating port for network c26503e9-b978-4f27-8153-89adee68b743"
}
    to retry, use: --limit @/home/dante/Openstack/roles/avi.retry

EDIT:

I had 2 previous tasks, to create a security group and assigned a rule to it, so no problems related to identity should be expected.

ansible 2.6.1 config file = /etc/ansible/ansible.cfg configured module search path = [u'/home/dante/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /bin/ansible python version = 2.7.5 (default, Jul 13 2018, 13:06:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

Any idea what can be be?

Many thanks, Romain


Solution

  • The solution was to upgrade the openstacksdk to 0.17.0 and update the code according to the SDK:

    sudo pip install openstacksdk==0.17.0

      - name: Create the Neutron ports
        os_port:
           state: present
           fixed_ips:
            - ip_address: 10.180.157.136
           allowed_address_pairs:
            - ip_address: 10.180.157.128/27
           name: port1
           security_groups: sg_default
           network: nw1
        tags: ports