Browse Source

Add support to setting image tags

Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/783849
Change-Id: Idee1f3c16cb07db39395b434d406628a9c5b152d
changes/50/783850/16
Dmitriy Rabotyagov 2 months ago
committed by Dmitriy Rabotyagov
parent
commit
6b3bf3bba0
4 changed files with 21 additions and 0 deletions
  1. +3
    -0
      ci/roles/image/defaults/main.yml
  2. +2
    -0
      ci/roles/image/tasks/main.yml
  3. +12
    -0
      plugins/modules/image.py
  4. +4
    -0
      plugins/modules/image_info.py

+ 3
- 0
ci/roles/image/defaults/main.yml View File

@ -1 +1,4 @@
image_name: ansible_image
image_tags:
- test
- ansible

+ 2
- 0
ci/roles/image/tasks/main.yml View File

@ -13,6 +13,7 @@
name: "{{ image_name }}"
filename: "{{ tmp_file.stdout }}"
disk_format: raw
tags: "{{ image_tags }}"
register: image
- name: Get details of created image
@ -25,6 +26,7 @@
assert:
that:
- "image_info_result.openstack_image.name == image_name"
- "image_info_result.openstack_image.tags | sort == image_tags | sort"
- name: Delete raw image (defaults)
openstack.cloud.image:


+ 12
- 0
plugins/modules/image.py View File

@ -85,6 +85,12 @@ options:
choices: [present, absent]
default: present
type: str
tags:
description:
- List of tags to be applied to the image
default: []
type: list
elements: str
volume:
description:
- ID of a volume to create an image from.
@ -115,6 +121,8 @@ EXAMPLES = '''
filename: cirros-0.3.0-x86_64-disk.img
kernel: cirros-vmlinuz
ramdisk: cirros-initrd
tags:
- custom
properties:
cpu_arch: x86_64
distro: ubuntu
@ -171,6 +179,7 @@ class ImageModule(OpenStackModule):
kernel=dict(type='str'),
properties=dict(type='dict', default={}),
volume=dict(type='str'),
tags=dict(type='list', default=[], elements='str'),
state=dict(default='present', choices=['absent', 'present']),
)
@ -205,6 +214,7 @@ class ImageModule(OpenStackModule):
min_disk=self.params['min_disk'],
min_ram=self.params['min_ram'],
volume=self.params['volume'],
tags=self.params['tags'],
**kwargs
)
changed = True
@ -217,6 +227,8 @@ class ImageModule(OpenStackModule):
ramdisk=self.params['ramdisk'],
protected=self.params['protected'],
**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)
self.exit(changed=changed, image=image, id=image.id)


+ 4
- 0
plugins/modules/image_info.py View File

@ -140,6 +140,10 @@ openstack_image:
description: Size of the image.
returned: success
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


Loading…
Cancel
Save