diff --git a/README.md b/README.md index d9a70b9..aec947d 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ Giving `module_openapi` as an input to Ansible.content builder scaffolding tool - *collection:path*: Destination folder where the user wants the output of the scaffolding tool to be stored. - *collection:namespace*: Ansible collection org name. - *collection:name*: Ansible collection name. +- *collection:requires_ansible*: The Ansible (core) version the collection requires (only used to generate `vmware.vmware_rest`). - *plugin:rm_swagger_json*: Swagger JSON/JSON file where OEMs API with all of its REST operations are defined. - *plugin:content*: The content that the builder generates (values: cloud/security default: security). - *plugin:api_object_path*: API for which resource module needs to be generated by the tool. When *plugin:content* is set to *cloud* this parameter should be set to the path of the schema files. @@ -218,6 +219,7 @@ collection: path: /collections/ansible_collections/vmware/vmware_rest namespace: vmware name: vmware_rest + requires_ansible: 2.14.0 plugins: - type: module_openapi name: "vmware_rest" diff --git a/changelogs/fragments/75-vmware_rest-action_groups.yaml b/changelogs/fragments/75-vmware_rest-action_groups.yaml new file mode 100644 index 0000000..dbe4b5a --- /dev/null +++ b/changelogs/fragments/75-vmware_rest-action_groups.yaml @@ -0,0 +1,3 @@ +minor_changes: + - "Add requires_ansible to manifest (https://github.com/ansible-community/ansible.content_builder/pull/76)." + - "Generate action_groups for the vmware.vmware_rest collection (https://github.com/ansible-community/ansible.content_builder/issues/75)." diff --git a/plugins/action/generate_cloud_modules.py b/plugins/action/generate_cloud_modules.py index f587701..b1298b7 100644 --- a/plugins/action/generate_cloud_modules.py +++ b/plugins/action/generate_cloud_modules.py @@ -36,6 +36,8 @@ ) # import for amazon.cloud doc generation from ansible_collections.ansible.content_builder.plugins.plugin_utils.cloud_utils.generator import generate_documentation +# import for vmware.vware_rest runtime.yml generation +from ansible_collections.ansible.content_builder.plugins.plugin_utils.cloud_utils.generator import generate_runtime_yml # vmware specific @@ -1325,6 +1327,15 @@ def generate_vmware_rest(args: Iterable, role_path: str): role_path=role_path ) module_list.append(module.name) + + print("Generating meta/runtime.yml") + runtime_yml = generate_runtime_yml(args.get("requires_ansible"), "vmware_rest", module_list) + meta_dir = pathlib.Path(args.get("target_dir") + "/meta") + meta_dir.mkdir(parents=True, exist_ok=True) + runtime_file = meta_dir / "runtime.yml" + with open(runtime_file, "w") as file: + yaml.safe_dump(runtime_yml, file, sort_keys=False) + return diff --git a/plugins/plugin_utils/cloud_utils/generator.py b/plugins/plugin_utils/cloud_utils/generator.py index 08bbda7..6b07ef8 100644 --- a/plugins/plugin_utils/cloud_utils/generator.py +++ b/plugins/plugin_utils/cloud_utils/generator.py @@ -268,6 +268,18 @@ def preprocess(self) -> Iterable: return sanitized_options +def generate_runtime_yml(requires_ansible, collection, module_list): + yaml_dict = { + "requires_ansible": (">=%s") % requires_ansible, + "action_groups": {collection: []}, + } + + for m in module_list: + yaml_dict["action_groups"][collection].append(m) + + return yaml_dict + + def generate_documentation( module: object, added_ins: Dict, next_version: str, target_dir: str ) -> Iterable: @@ -399,4 +411,4 @@ def generate_docs(self, type_name: str): # TODO: include version response = self.client.describe_type(Type="RESOURCE", TypeName=type_name) - return response.get("Schema") \ No newline at end of file + return response.get("Schema") diff --git a/roles/module_openapi_cloud/tasks/main.yaml b/roles/module_openapi_cloud/tasks/main.yaml index ed3370a..0ccec6d 100644 --- a/roles/module_openapi_cloud/tasks/main.yaml +++ b/roles/module_openapi_cloud/tasks/main.yaml @@ -14,6 +14,7 @@ schema_dir: "{{ plugin['api_object_path'] }}" modules: "{{ plugin['resource'] }}" next_version: "{{ plugin['module_version'] }}" + requires_ansible: "{{ collection['requires_ansible'] }}" changed_when: false when: ( plugin['action'] == 'generate_modules' ) or ( plugin['action'] == 'generate_all' ) diff --git a/roles/run/files/schema.json b/roles/run/files/schema.json index b8bd177..655a0a0 100644 --- a/roles/run/files/schema.json +++ b/roles/run/files/schema.json @@ -21,7 +21,22 @@ "path", "namespace", "name" - ] + ], + "if": { + "properties": { + "name": { + "const": "vmware_rest" + } + } + }, + "then": { + "properties": { + "requires_ansible": { + "type": "string" + } + }, + "required": ["requires_ansible"] + } }, "license_file": { "type": "string" diff --git a/tests/cloud/test_generator.py b/tests/cloud/test_generator.py index f07df4d..a940059 100644 --- a/tests/cloud/test_generator.py +++ b/tests/cloud/test_generator.py @@ -69,3 +69,8 @@ def test_generate_documentation(): Path("tests/cloud/fixtures"), ) assert documentation == expected_content + + +def test_generate_runtime_yml(): + runtime_yml = g.generate_runtime_yml("1.2.3", "test", ["foo", "bar"]) + assert runtime_yml == {"requires_ansible": ">=1.2.3", "action_groups": {"test": ["foo", "bar"]}}