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 | |
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
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | awx_collection/template_galaxy.yml | 47 | ||||
-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 (renamed from awx_collection/galaxy.yml.j2) | 0 | ||||
-rw-r--r-- | awx_collection/tools/template_galaxy.yml | 12 |
8 files changed, 115 insertions, 113 deletions
@@ -393,7 +393,7 @@ symlink_collection: ln -s $(shell pwd)/awx_collection $(COLLECTION_INSTALL) build_collection: - ansible-playbook -i localhost, awx_collection/template_galaxy.yml -e collection_package=$(COLLECTION_PACKAGE) -e collection_namespace=$(COLLECTION_NAMESPACE) -e collection_version=$(VERSION) + ansible-playbook -i localhost, awx_collection/tools/template_galaxy.yml -e collection_package=$(COLLECTION_PACKAGE) -e collection_namespace=$(COLLECTION_NAMESPACE) -e collection_version=$(VERSION) ansible-galaxy collection build awx_collection --force --output-path=awx_collection install_collection: build_collection diff --git a/awx_collection/template_galaxy.yml b/awx_collection/template_galaxy.yml deleted file mode 100644 index a9b042b903..0000000000 --- a/awx_collection/template_galaxy.yml +++ /dev/null @@ -1,47 +0,0 @@ ---- -- 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 - - tasks: - - name: Set the collection version in the tower_api.py file - replace: - path: "{{ playbook_dir }}/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: "{{ playbook_dir }}/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: "{{ playbook_dir }}/plugins/modules/tower_*.py" - loop_control: - label: "{{ item | basename }}" - - - name: Change inventory file to support desired namespace and package names - replace: - path: "{{ playbook_dir }}/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: "{{ playbook_dir }}/galaxy.yml.j2" - dest: "{{ playbook_dir }}/galaxy.yml" - force: true 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/galaxy.yml.j2 b/awx_collection/tools/roles/template_galaxy/templates/galaxy.yml.j2 index b2a00538d7..b2a00538d7 100644 --- a/awx_collection/galaxy.yml.j2 +++ b/awx_collection/tools/roles/template_galaxy/templates/galaxy.yml.j2 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 |