Add support to setting image tags
Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/783849 Change-Id: Idee1f3c16cb07db39395b434d406628a9c5b152d
This commit is contained in:
parent
daaa6bf561
commit
6b3bf3bba0
@ -1 +1,4 @@
|
|||||||
image_name: ansible_image
|
image_name: ansible_image
|
||||||
|
image_tags:
|
||||||
|
- test
|
||||||
|
- ansible
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
name: "{{ image_name }}"
|
name: "{{ image_name }}"
|
||||||
filename: "{{ tmp_file.stdout }}"
|
filename: "{{ tmp_file.stdout }}"
|
||||||
disk_format: raw
|
disk_format: raw
|
||||||
|
tags: "{{ image_tags }}"
|
||||||
register: image
|
register: image
|
||||||
|
|
||||||
- name: Get details of created image
|
- name: Get details of created image
|
||||||
@ -25,6 +26,7 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "image_info_result.openstack_image.name == image_name"
|
- "image_info_result.openstack_image.name == image_name"
|
||||||
|
- "image_info_result.openstack_image.tags | sort == image_tags | sort"
|
||||||
|
|
||||||
- name: Delete raw image (defaults)
|
- name: Delete raw image (defaults)
|
||||||
openstack.cloud.image:
|
openstack.cloud.image:
|
||||||
|
@ -85,6 +85,12 @@ options:
|
|||||||
choices: [present, absent]
|
choices: [present, absent]
|
||||||
default: present
|
default: present
|
||||||
type: str
|
type: str
|
||||||
|
tags:
|
||||||
|
description:
|
||||||
|
- List of tags to be applied to the image
|
||||||
|
default: []
|
||||||
|
type: list
|
||||||
|
elements: str
|
||||||
volume:
|
volume:
|
||||||
description:
|
description:
|
||||||
- ID of a volume to create an image from.
|
- ID of a volume to create an image from.
|
||||||
@ -115,6 +121,8 @@ EXAMPLES = '''
|
|||||||
filename: cirros-0.3.0-x86_64-disk.img
|
filename: cirros-0.3.0-x86_64-disk.img
|
||||||
kernel: cirros-vmlinuz
|
kernel: cirros-vmlinuz
|
||||||
ramdisk: cirros-initrd
|
ramdisk: cirros-initrd
|
||||||
|
tags:
|
||||||
|
- custom
|
||||||
properties:
|
properties:
|
||||||
cpu_arch: x86_64
|
cpu_arch: x86_64
|
||||||
distro: ubuntu
|
distro: ubuntu
|
||||||
@ -171,6 +179,7 @@ class ImageModule(OpenStackModule):
|
|||||||
kernel=dict(type='str'),
|
kernel=dict(type='str'),
|
||||||
properties=dict(type='dict', default={}),
|
properties=dict(type='dict', default={}),
|
||||||
volume=dict(type='str'),
|
volume=dict(type='str'),
|
||||||
|
tags=dict(type='list', default=[], elements='str'),
|
||||||
state=dict(default='present', choices=['absent', 'present']),
|
state=dict(default='present', choices=['absent', 'present']),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -205,6 +214,7 @@ class ImageModule(OpenStackModule):
|
|||||||
min_disk=self.params['min_disk'],
|
min_disk=self.params['min_disk'],
|
||||||
min_ram=self.params['min_ram'],
|
min_ram=self.params['min_ram'],
|
||||||
volume=self.params['volume'],
|
volume=self.params['volume'],
|
||||||
|
tags=self.params['tags'],
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
changed = True
|
changed = True
|
||||||
@ -217,6 +227,8 @@ class ImageModule(OpenStackModule):
|
|||||||
ramdisk=self.params['ramdisk'],
|
ramdisk=self.params['ramdisk'],
|
||||||
protected=self.params['protected'],
|
protected=self.params['protected'],
|
||||||
**self.params['properties'])
|
**self.params['properties'])
|
||||||
|
if self.params['tags']:
|
||||||
|
self.conn.image.update_image(image.id, tags=self.params['tags'])
|
||||||
image = self.conn.get_image(name_or_id=image.id)
|
image = self.conn.get_image(name_or_id=image.id)
|
||||||
self.exit(changed=changed, image=image, id=image.id)
|
self.exit(changed=changed, image=image, id=image.id)
|
||||||
|
|
||||||
|
@ -140,6 +140,10 @@ openstack_image:
|
|||||||
description: Size of the image.
|
description: Size of the image.
|
||||||
returned: success
|
returned: success
|
||||||
type: int
|
type: int
|
||||||
|
tags:
|
||||||
|
description: List of tags assigned to the image
|
||||||
|
returned: success
|
||||||
|
type: list
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||||
|
Loading…
x
Reference in New Issue
Block a user