Rework some of our package tooling

This commit is contained in:
Caleb Boylan 2020-04-30 14:22:02 -07:00 committed by AlanCoding
parent 6a9423626c
commit 7478a2aa5e
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
8 changed files with 115 additions and 113 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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