mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 15:02:07 -03:30
Rework some of our package tooling
This commit is contained in:
parent
6a9423626c
commit
7478a2aa5e
2
Makefile
2
Makefile
@ -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
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
63
awx_collection/tools/roles/generate/tasks/main.yml
Normal file
63
awx_collection/tools/roles/generate/tasks/main.yml
Normal 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'
|
||||
37
awx_collection/tools/roles/template_galaxy/tasks/main.yml
Normal file
37
awx_collection/tools/roles/template_galaxy/tasks/main.yml
Normal 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
|
||||
12
awx_collection/tools/template_galaxy.yml
Normal file
12
awx_collection/tools/template_galaxy.yml
Normal 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
|
||||
Loading…
x
Reference in New Issue
Block a user