From f1a1b72f070b6ee83af977eddf0cf7881325d330 Mon Sep 17 00:00:00 2001 From: Maxim Babushkin Date: Mon, 2 Sep 2019 12:07:53 +0300 Subject: [PATCH] os_server - add "tag" to instance nics (#61119) A custom "tag" could be passed to the instance metadata with the nics. Add support for the "tag" to the module. --- ...119-os_server-add-tag-to-instance-nics.yml | 2 ++ .../modules/cloud/openstack/os_server.py | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/61119-os_server-add-tag-to-instance-nics.yml diff --git a/changelogs/fragments/61119-os_server-add-tag-to-instance-nics.yml b/changelogs/fragments/61119-os_server-add-tag-to-instance-nics.yml new file mode 100644 index 00000000000..92c4474f4ff --- /dev/null +++ b/changelogs/fragments/61119-os_server-add-tag-to-instance-nics.yml @@ -0,0 +1,2 @@ +minor_changes: + - os_server - add ``tag`` to instance nics diff --git a/lib/ansible/modules/cloud/openstack/os_server.py b/lib/ansible/modules/cloud/openstack/os_server.py index 148bb9117e0..f6b7b9ef140 100644 --- a/lib/ansible/modules/cloud/openstack/os_server.py +++ b/lib/ansible/modules/cloud/openstack/os_server.py @@ -76,6 +76,12 @@ options: - 'Also this accepts a string containing a list of (net/port)-(id/name) Eg: nics: "net-id=uuid-1,port-name=myport" Only one of network or nics should be supplied.' + suboptions: + tag: + description: + - 'A "tag" for the specific port to be passed via metadata. + Eg: tag: test_tag' + version_added: "2.9" auto_ip: description: - Ensure instance has public ip however the cloud wants to do that @@ -396,6 +402,24 @@ EXAMPLES = ''' scheduler_hints: group: f5c8c61a-9230-400a-8ed2-3b023c190a7f +# Create an instance with "tags" for the nic +- name: Create instance with nics "tags" + os_server: + state: present + auth: + auth_url: https://identity.example.com + username: admin + password: admin + project_name: admin + name: vm1 + image: 4f905f38-e52a-43d2-b6ec-754a13ffb529 + key_name: ansible_key + flavor: 4 + nics: + - port-name: net1_port1 + tag: test_tag + - net-name: another_network + # Deletes an instance via its ID - name: remove an instance hosts: localhost @@ -435,7 +459,7 @@ def _network_args(module, cloud): if not isinstance(nics, list): module.fail_json(msg='The \'nics\' parameter must be a list.') - for net in _parse_nics(nics): + for num, net in enumerate(_parse_nics(nics)): if not isinstance(net, dict): module.fail_json( msg='Each entry in the \'nics\' parameter must be a dict.') @@ -464,6 +488,9 @@ def _network_args(module, cloud): del resolved_net['port-name'] resolved_net['port-id'] = by_name['id'] args.append(resolved_net) + + if 'tag' in net: + args[num]['tag'] = net['tag'] return args