diff options
author | Caleb Boylan <calebboylan@gmail.com> | 2020-04-30 23:22:02 +0200 |
---|---|---|
committer | AlanCoding <arominge@redhat.com> | 2020-05-15 15:26:33 +0200 |
commit | 7478a2aa5eb67a3fc4cb4fce852b1a434fb1b073 (patch) | |
tree | 557d5a7fab7df50f174981c0933e15d53111de5b /awx_collection/tools | |
parent | Add field numbering specification in module_util file, update unit tests (diff) | |
download | awx-7478a2aa5eb67a3fc4cb4fce852b1a434fb1b073.tar.xz awx-7478a2aa5eb67a3fc4cb4fce852b1a434fb1b073.zip |
Rework some of our package tooling
Diffstat (limited to 'awx_collection/tools')
-rw-r--r-- | awx_collection/tools/generate.yml | 67 | ||||
-rw-r--r-- | awx_collection/tools/roles/generate/tasks/main.yml | 63 | ||||
-rw-r--r-- | awx_collection/tools/roles/generate/templates/tower_module.j2 (renamed from awx_collection/tools/templates/tower_module.j2) | 0 | ||||
-rw-r--r-- | awx_collection/tools/roles/template_galaxy/tasks/main.yml | 37 | ||||
-rw-r--r-- | awx_collection/tools/roles/template_galaxy/templates/galaxy.yml.j2 | 26 | ||||
-rw-r--r-- | awx_collection/tools/template_galaxy.yml | 12 |
6 files changed, 140 insertions, 65 deletions
diff --git a/awx_collection/tools/generate.yml b/awx_collection/tools/generate.yml index a65f64b402..4a592ae87f 100644 --- a/awx_collection/tools/generate.yml +++ b/awx_collection/tools/generate.yml @@ -17,68 +17,5 @@ force_basic_auth: true url_username: "{{ lookup('env', 'TOWER_USERNAME') }}" url_password: "{{ lookup('env', 'TOWER_PASSWORD') }}" - - tasks: - - name: Get date time data - setup: - gather_subset: min - - - name: Create module directory - file: - state: directory - name: "modules" - - - name: Load api/v2 - uri: - method: GET - url: "{{ api_url }}/api/v2/" - register: endpoints - - - name: Load endpoint options - uri: - method: "OPTIONS" - url: "{{ api_url }}{{ item.value }}" - loop: "{{ endpoints['json'] | dict2items }}" - loop_control: - label: "{{ item.key }}" - register: end_point_options - when: "generate_for is not defined or item.key in generate_for" - - - name: Scan POST options for different things - set_fact: - all_options: "{{ all_options | default({}) | combine(options[0]) }}" - loop: "{{ end_point_options.results }}" - vars: - options: "{{ item | json_query('json.actions.POST.[*]') }}" - loop_control: - label: "{{ item['item']['key'] }}" - when: - - item is not skipped - - options is defined - - - name: Process endpoint - template: - src: "templates/tower_module.j2" - dest: "{{ playbook_dir | dirname }}/plugins/modules/{{ file_name }}" - loop: "{{ end_point_options['results'] }}" - loop_control: - label: "{{ item['item']['key'] }}" - when: "'json' in item and 'actions' in item['json'] and 'POST' in item['json']['actions']" - vars: - item_type: "{{ item['item']['key'] }}" - human_readable: "{{ item_type | replace('_', ' ') }}" - singular_item_type: "{{ item['item']['key'] | regex_replace('ies$', 'y') | regex_replace('s$', '') }}" - file_name: "tower_{% if item['item']['key'] in ['settings'] %}{{ item['item']['key'] }}{% else %}{{ singular_item_type }}{% endif %}.py" - type_map: - bool: 'bool' - boolean: 'bool' - choice: 'str' - datetime: 'str' - id: 'str' - int: 'int' - integer: 'int' - json: 'dict' - list: 'list' - object: 'dict' - password: 'str' - string: 'str' + roles: + - generate diff --git a/awx_collection/tools/roles/generate/tasks/main.yml b/awx_collection/tools/roles/generate/tasks/main.yml new file mode 100644 index 0000000000..8e123af6ec --- /dev/null +++ b/awx_collection/tools/roles/generate/tasks/main.yml @@ -0,0 +1,63 @@ + - name: Get date time data + setup: + gather_subset: min + + - name: Create module directory + file: + state: directory + name: "modules" + + - name: Load api/v2 + uri: + method: GET + url: "{{ api_url }}/api/v2/" + register: endpoints + + - name: Load endpoint options + uri: + method: "OPTIONS" + url: "{{ api_url }}{{ item.value }}" + loop: "{{ endpoints['json'] | dict2items }}" + loop_control: + label: "{{ item.key }}" + register: end_point_options + when: "generate_for is not defined or item.key in generate_for" + + - name: Scan POST options for different things + set_fact: + all_options: "{{ all_options | default({}) | combine(options[0]) }}" + loop: "{{ end_point_options.results }}" + vars: + options: "{{ item | json_query('json.actions.POST.[*]') }}" + loop_control: + label: "{{ item['item']['key'] }}" + when: + - item is not skipped + - options is defined + + - name: Process endpoint + template: + src: "templates/tower_module.j2" + dest: "{{ playbook_dir | dirname }}/plugins/modules/{{ file_name }}" + loop: "{{ end_point_options['results'] }}" + loop_control: + label: "{{ item['item']['key'] }}" + when: "'json' in item and 'actions' in item['json'] and 'POST' in item['json']['actions']" + vars: + item_type: "{{ item['item']['key'] }}" + human_readable: "{{ item_type | replace('_', ' ') }}" + singular_item_type: "{{ item['item']['key'] | regex_replace('ies$', 'y') | regex_replace('s$', '') }}" + file_name: "tower_{% if item['item']['key'] in ['settings'] %}{{ item['item']['key'] }}{% else %}{{ singular_item_type }}{% endif %}.py" + type_map: + bool: 'bool' + boolean: 'bool' + choice: 'str' + datetime: 'str' + id: 'str' + int: 'int' + integer: 'int' + json: 'dict' + list: 'list' + object: 'dict' + password: 'str' + string: 'str' diff --git a/awx_collection/tools/templates/tower_module.j2 b/awx_collection/tools/roles/generate/templates/tower_module.j2 index 5d687bfc24..5d687bfc24 100644 --- a/awx_collection/tools/templates/tower_module.j2 +++ b/awx_collection/tools/roles/generate/templates/tower_module.j2 diff --git a/awx_collection/tools/roles/template_galaxy/tasks/main.yml b/awx_collection/tools/roles/template_galaxy/tasks/main.yml new file mode 100644 index 0000000000..425bf8fd29 --- /dev/null +++ b/awx_collection/tools/roles/template_galaxy/tasks/main.yml @@ -0,0 +1,37 @@ +- name: Set the collection version in the tower_api.py file + replace: + path: "{{ collection_path }}/plugins/module_utils/tower_api.py" + regexp: '^ _COLLECTION_VERSION =.*' + replace: ' _COLLECTION_VERSION = "{{ collection_version }}"' + +- name: Set the collection type in the tower_api.py file + replace: + path: "{{ collection_path }}/plugins/module_utils/tower_api.py" + regexp: '^ _COLLECTION_TYPE =.*' + replace: ' _COLLECTION_TYPE = "{{ collection_namespace }}"' + +- name: Do file content replacements for non-default namespace or package name + block: + + - name: Change module doc_fragments to support desired namespace and package names + replace: + path: "{{ item }}" + regexp: '^extends_documentation_fragment: awx.awx.auth$' + replace: 'extends_documentation_fragment: {{ collection_namespace }}.{{ collection_package }}.auth' + with_fileglob: "{{ collection_path }}/plugins/modules/tower_*.py" + loop_control: + label: "{{ item | basename }}" + + - name: Change inventory file to support desired namespace and package names + replace: + path: "{{ collection_path }}/plugins/inventory/tower.py" + regexp: "^ NAME = 'awx.awx.tower' # REPLACE$" + replace: " NAME = '{{ collection_namespace }}.{{ collection_package }}.tower' # REPLACE" + when: + - (collection_package != 'awx') or (collection_namespace != 'awx') + +- name: Template the galaxy.yml file + template: + src: "{{ collection_path }}/tools/roles/template_galaxy/templates/galaxy.yml.j2" + dest: "{{ collection_path }}/galaxy.yml" + force: true diff --git a/awx_collection/tools/roles/template_galaxy/templates/galaxy.yml.j2 b/awx_collection/tools/roles/template_galaxy/templates/galaxy.yml.j2 new file mode 100644 index 0000000000..b2a00538d7 --- /dev/null +++ b/awx_collection/tools/roles/template_galaxy/templates/galaxy.yml.j2 @@ -0,0 +1,26 @@ +authors: +- AWX Project Contributors <awx-project@googlegroups.com> +dependencies: {} +description: Ansible content that interacts with the AWX or Ansible Tower API. +documentation: https://github.com/ansible/awx/blob/devel/awx_collection/README.md +homepage: https://www.ansible.com/ +issues: https://github.com/ansible/awx/issues?q=is%3Aissue+label%3Acomponent%3Aawx_collection +license: +- GPL-3.0-only +name: {{ collection_package }} +namespace: {{ collection_namespace }} +readme: README.md +repository: https://github.com/ansible/awx +tags: +- cloud +- infrastructure +- awx +- ansible +- automation +version: {{ collection_version }} +build_ignore: +- tools +- setup.cfg +- galaxy.yml.j2 +- template_galaxy.yml +- '*.tar.gz' diff --git a/awx_collection/tools/template_galaxy.yml b/awx_collection/tools/template_galaxy.yml new file mode 100644 index 0000000000..78b69cfa5f --- /dev/null +++ b/awx_collection/tools/template_galaxy.yml @@ -0,0 +1,12 @@ +--- +- name: Template the collection galaxy.yml + hosts: localhost + gather_facts: false + connection: local + vars: + collection_package: awx + collection_namespace: awx + collection_version: 0.0.1 # not for updating, pass in extra_vars + collection_path: "{{ playbook_dir }}/../" + roles: + - template_galaxy |