使用 Ansible 和 Openstack Packstack 创建 Neutron 端口

Create Neutron port using Ansible and Openstack Packstack

我正在尝试在 Ansible 中重现这个 Openstack 命令:

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

我已经尝试过创建这个 Openstack 命令的任务:

  - 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

如果我运行正在使用 Openstack 命令,则效果很好。如果我尝试 运行 这个特定任务,它会失败并出现以下错误:

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

在详细模式下:

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

编辑:

我之前有 2 个任务,创建一个安全组并为其分配规则,因此应该不会出现与身份相关的问题。

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)]

知道会是什么吗?

非常感谢, 罗曼

解决方法是将openstacksdk升级到0.17.0,并根据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