Read decompressed metadata with ansible tasks
Using custom ansible module within zuul is not straightforward, using ansible tasks to simplify things. Change-Id: I90845a148c007657d2ce4faf191b1e46264432af
This commit is contained in:
parent
18d5e2fbb3
commit
0a4f479eda
@ -1,2 +0,0 @@
|
||||
[defaults]
|
||||
library = ./ansible_library
|
@ -1,48 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2024 Canonical Ltd.
|
||||
|
||||
import pathlib
|
||||
import zipfile
|
||||
|
||||
import yaml
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
module: charm_metadata
|
||||
author: Canonical
|
||||
description: Read charm metadata from a charm artifact
|
||||
|
||||
options:
|
||||
path:
|
||||
description: path to charm artifact
|
||||
required: yes
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
- name: Read charm metadata
|
||||
charm_metadata:
|
||||
charm: /tmp/keystone.charm
|
||||
"""
|
||||
|
||||
|
||||
def run_module():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
path=dict(type="str", required=True),
|
||||
)
|
||||
)
|
||||
|
||||
path: str = module.params["path"] # type: ignore
|
||||
charm_path = pathlib.Path(path)
|
||||
if not charm_path.exists():
|
||||
module.fail_json(msg=f"charm {path} not found on disk")
|
||||
|
||||
with zipfile.ZipFile(charm_path, "r") as charm_zip:
|
||||
metadata = charm_zip.read("metadata.yaml")
|
||||
metadata_dict = yaml.safe_load(metadata)
|
||||
|
||||
module.exit_json(changed=False, metadata=metadata_dict)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_module()
|
@ -19,15 +19,24 @@
|
||||
include_role:
|
||||
name: ensure-docker
|
||||
|
||||
- name: Get metadata.yaml information
|
||||
charm_metadata:
|
||||
path: "{{ zuul.project.src_dir }}/{{ charm_build_name }}.charm"
|
||||
register: charm_metadata
|
||||
- name: Set project absolute path
|
||||
set_fact:
|
||||
project_abs: "{{ zuul.executor.work_root }}/{{ zuul.project.src_dir }}"
|
||||
|
||||
- name: Create charm destination folder
|
||||
file:
|
||||
path: "{{ project_abs }}/{{ charm_build_name }}"
|
||||
state: directory
|
||||
|
||||
- name: Decompress charm
|
||||
unarchive:
|
||||
src: "{{ project_abs }}/{{ charm_build_name }}.charm"
|
||||
dest: "{{ project_abs }}/{{ charm_build_name }}"
|
||||
|
||||
- name: Upload oci-image to charmhub
|
||||
register: upload_oci_image_output
|
||||
vars:
|
||||
metadata: "{{ charm_metadata['metadata'] }}"
|
||||
metadata: "{{ lookup('file', project_abs + '/' + charm_build_name + '/metadata.yaml') | from_yaml }}"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
shell: |
|
||||
|
Loading…
x
Reference in New Issue
Block a user