diff --git a/README.md b/README.md index 674b37f..5c8519d 100644 --- a/README.md +++ b/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:\ +Creates a new collection `` 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:\ +Creates a new role `` 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. diff --git a/Taskfile.yml b/Taskfile.yml index cdd2adf..42cf6e7 100644 --- a/Taskfile.yml +++ b/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'