feat(tooling): added tasks to generate a new ansible role or collection with default skeleton
This commit is contained in:
parent
317c562e7a
commit
fc11d3ee83
2 changed files with 35 additions and 9 deletions
26
README.md
26
README.md
|
@ -100,6 +100,23 @@ Run Ansible's sanity tests on each collections declared in `collections/ansible_
|
|||
#### nosey
|
||||
Run `noseyparker`, a tool that aims to find potential data leak such as passwords and security token.
|
||||
|
||||
#### ansible:new:collection:\<name\>
|
||||
Creates a new collection `<name>` and add an exception in .gitignore in order to let git track it.
|
||||
Example:
|
||||
```shell
|
||||
task ansible:new:collection:my_org.my_collection
|
||||
```
|
||||
|
||||
#### ansible:new:role:\<name\>
|
||||
Creates a new role `<name>` in the default or specified collection.
|
||||
Examples:
|
||||
```shell
|
||||
#New role for the default (nullified.infrastructure) collection
|
||||
task ansible:new:role:my_new_role
|
||||
# New role the collection "my_org.my_collection"
|
||||
COLLECTION_NAME=my_org.my_collection task ansible:new:role:my_new_role
|
||||
```
|
||||
|
||||
### Examples
|
||||
```shell
|
||||
# encrypt vault
|
||||
|
@ -112,15 +129,6 @@ task venv -- ansible-playbook --ask-vault-password -l my_host playbooks/test.yml
|
|||
task venv -- ansible --ask-vault-password -m import_role --args 'name=nullified.infrastructure.security' my_host
|
||||
```
|
||||
|
||||
### Generic collection / roles commands
|
||||
```shell
|
||||
mkdir -p collections/ansible_collections
|
||||
cd collections/ansible_collections
|
||||
task venv -- ansible-galaxy collection init nullified.infrastructure
|
||||
cd nullified/infrastructure/roles
|
||||
task venv -- ansible-galaxy collection init tooling
|
||||
```
|
||||
|
||||
## Advanced Configuration
|
||||
### Global variables
|
||||
Global variables are defined in `inventory/group_vars/all/vars.yml` and are used in multiple roles and playbooks.
|
||||
|
|
18
Taskfile.yml
18
Taskfile.yml
|
@ -6,6 +6,7 @@ env:
|
|||
vars:
|
||||
PYTHON_WRAPPER: '{{.ROOT_DIR}}/scripts/python_wrapper.sh'
|
||||
MOLECULE_DIR: '{{.ROOT_DIR}}/collections/ansible_collections/nullified/infrastructure/extensions'
|
||||
COLLECTIONS_DIR: '{{.ROOT_DIR}}/collections/ansible_collections'
|
||||
|
||||
tasks:
|
||||
setup:venv:
|
||||
|
@ -117,3 +118,20 @@ tasks:
|
|||
desc: execute a molecule command
|
||||
dir: '{{.MOLECULE_DIR}}'
|
||||
cmd: '{{.PYTHON_WRAPPER}} molecule {{.CLI_ARGS}}'
|
||||
|
||||
ansible:new:role:*:
|
||||
desc: create a new role for the specified collection
|
||||
vars:
|
||||
COLLECTION_NAME: '{{default "nullified.infrastructure" .COLLECTION_NAME}}'
|
||||
ROLE_NAME: '{{index .MATCH 0}}'
|
||||
cmds:
|
||||
- '{{.PYTHON_WRAPPER}} ansible-galaxy role init {{.ROLE_NAME}} --init-path {{.COLLECTIONS_DIR}}/{{.COLLECTION_NAME | replace "." "/"}}/roles'
|
||||
|
||||
ansible:new:collection:*:
|
||||
desc: create a new collection
|
||||
vars:
|
||||
COLLECTION_NAME: '{{index .MATCH 0}}'
|
||||
COLLECTION_SUBPATH: 'collections/ansible_collections'
|
||||
cmds:
|
||||
- '{{.PYTHON_WRAPPER}} ansible-galaxy collection init {{.COLLECTION_NAME}} --init-path {{.COLLECTIONS_DIR}}'
|
||||
- 'echo "!{{.COLLECTION_SUBPATH}}/{{(.COLLECTION_NAME | split ".")._0}}" | tee -a .gitignore > /dev/null'
|
||||
|
|
Loading…
Add table
Reference in a new issue