From ebfec43312d229a99025117eed19f6f4c5f047e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sachse?= <joerg.sachse@slub-dresden.de> Date: Fri, 5 Apr 2024 16:52:37 +0200 Subject: [PATCH] use namespace/collection --- README.md | 83 +------------------ galaxy.yml | 69 +++++++++++++++ meta/runtime.yml | 52 ++++++++++++ plugins/README.md | 31 +++++++ .../ansible_slub_awxdemo01/.gitattributes | 0 .../.githooks}/pre-commit | 0 .../ansible_slub_awxdemo01/.gitignore | 0 .../ansible_slub_awxdemo01/.yamllint | 0 .../ansible_slub_awxdemo01/LICENSE | 0 roles/ansible_slub_awxdemo01/README.md | 82 ++++++++++++++++++ .../ansible_slub_awxdemo01/ansible.cfg | 0 .../ansible_slub_awxdemo01/defaults}/main.yml | 0 .../ansible_slub_awxdemo01/handlers}/main.yml | 0 .../ansible_slub_awxdemo01/meta}/main.yml | 0 .../molecule}/default/Dockerfile.j2 | 0 .../molecule}/default/INSTALL.rst | 0 .../molecule}/default/molecule.yml | 0 .../molecule}/default/playbook.yml | 0 .../molecule}/default/tests/test_default.py | 0 .../ansible_slub_awxdemo01/setup_gitconfig.sh | 0 .../ansible_slub_awxdemo01/site.yml | 0 .../ansible_slub_awxdemo01/tasks}/main.yml | 0 .../ansible_slub_awxdemo01/vars}/main.yml | 0 23 files changed, 236 insertions(+), 81 deletions(-) create mode 100644 galaxy.yml create mode 100644 meta/runtime.yml create mode 100644 plugins/README.md rename .gitattributes => roles/ansible_slub_awxdemo01/.gitattributes (100%) rename {.githooks => roles/ansible_slub_awxdemo01/.githooks}/pre-commit (100%) rename .gitignore => roles/ansible_slub_awxdemo01/.gitignore (100%) rename .yamllint => roles/ansible_slub_awxdemo01/.yamllint (100%) rename LICENSE => roles/ansible_slub_awxdemo01/LICENSE (100%) create mode 100644 roles/ansible_slub_awxdemo01/README.md rename ansible.cfg => roles/ansible_slub_awxdemo01/ansible.cfg (100%) rename {defaults => roles/ansible_slub_awxdemo01/defaults}/main.yml (100%) rename {handlers => roles/ansible_slub_awxdemo01/handlers}/main.yml (100%) rename {meta => roles/ansible_slub_awxdemo01/meta}/main.yml (100%) rename {molecule => roles/ansible_slub_awxdemo01/molecule}/default/Dockerfile.j2 (100%) rename {molecule => roles/ansible_slub_awxdemo01/molecule}/default/INSTALL.rst (100%) rename {molecule => roles/ansible_slub_awxdemo01/molecule}/default/molecule.yml (100%) rename {molecule => roles/ansible_slub_awxdemo01/molecule}/default/playbook.yml (100%) rename {molecule => roles/ansible_slub_awxdemo01/molecule}/default/tests/test_default.py (100%) rename setup_gitconfig.sh => roles/ansible_slub_awxdemo01/setup_gitconfig.sh (100%) rename site.yml => roles/ansible_slub_awxdemo01/site.yml (100%) rename {tasks => roles/ansible_slub_awxdemo01/tasks}/main.yml (100%) rename {vars => roles/ansible_slub_awxdemo01/vars}/main.yml (100%) diff --git a/README.md b/README.md index d6e59a2..3eb3460 100644 --- a/README.md +++ b/README.md @@ -1,82 +1,3 @@ -# Ansible-Role "ansible_slub_awxdemo01" +# Ansible Collection - my_namespace.my_collection -## Description - -AWX Demo role (read-only tasks to show off). - -## Prerequisites - -To use this role, the following software must be installed on your workstation: -* ansible - -To deploy this role to a managed host, the following software must be installed on the target: -* Python3 -* SSHd - -It is recommended to use Debian VMs as deployed by SLUB's UDA tool with this role. Otherwise you will not have access to the software packages that are located in SLUB's private Debian package repository. - -## Quick Start - -``` - ansible-playbook site.yml [--limit <HOSTNAME>] [-u <USERNAME>] -``` - -## General Ansible usage - -Most options already have sensible defaults in `ansible.cfg`. However, you can override these defaults using CLI options/flags if you want to. - -To simply run the playbook, just call the `site.yml` playbook like this: -``` - ansible-playbook site.yml -u <username> -``` - -If you want to limit the execution to a subset of all hosts that are listed in the inventory, use the `-l` or `--limit` option like this: -``` - ansible-playbook site.yml -l <hostna*> - ansible-playbook site.yml -l <hostname> - ansible-playbook site.yml -l <hostname1>:<hostname2>:... - ansible-playbook site.yml -l <inventory_group> - ansible-playbook site.yml --limit=<hostna*> -``` - -If you do not have Vault password files in the directory above the role direcory, you have to give the Vault password before execution: -``` - ansible-playbook site.yml --ask-vault-pass -``` - -You can use your own inventory file by adding the `-i` or `--inventory=INVENTORY` option: -``` - ansible-playbook site.yml -i inventory.yml - ansible-playbook site.yml --inventory=inventory.yml -``` - -Tasks in this role have been tagged to enable users to only run subsets of tasks. This can be leveraged to decrease run times or run only certain tasks after small changes. -To list all available tags, use: -``` - ansible-playbook site.yml --list-tags -``` -You can then run only certain tagged tasks by using the `--tags` option: -``` - ansible-playbook site.yml -t tag1,tag2,...,tagN - ansible-playbook site.yml --tags=tag1,tag2,...,tagN -``` - -For more help with ansible-playbook, use the `--help` flag. - -## Testing the role - -The test framework has been prepared using the Molecule framework. The details on using the test suite are described below `molecule/`. - -## Variables - -Some variables have been "hidden" in encrypted Ansible Vaults. For security reasons, these Vaults are maintained in a separate private internal repository of SLUB's Git. However, in order to better understand the data within the vaults, you can find `\*.vault.example` files below the `vars/` directory. - -If you work outside of SLUBArchiv and have no access to the vault repository, make sure to put the necessary vaults in the expected paths at `../ansible_vaults/<ROLENAME>/`, as that's where this role expects to find them. - -## git configuration - -Just run the `setup_gitconfig.sh` script that comes with the repo to correctly setup all necessary local Git configurations. - -## Author Information - -If you have any comments or find bugs, please contact Joerg.Sachse@slub-dresden.de, open an issue or open a pull request. +Documentation for the collection. diff --git a/galaxy.yml b/galaxy.yml new file mode 100644 index 0000000..dbe3c8a --- /dev/null +++ b/galaxy.yml @@ -0,0 +1,69 @@ +### REQUIRED +# The namespace of the collection. This can be a company/brand/organization or product namespace under which all +# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with +# underscores or numbers and cannot contain consecutive underscores +namespace: my_namespace + +# The name of the collection. Has the same character restrictions as 'namespace' +name: my_collection + +# The version of the collection. Must be compatible with semantic versioning +version: 1.0.0 + +# The path to the Markdown (.md) readme file. This path is relative to the root of the collection +readme: README.md + +# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url) +# @nicks:irc/im.site#channel' +authors: +- your name <example@domain.com> + + +### OPTIONAL but strongly recommended +# A short summary description of the collection +description: your collection description + +# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only +# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file' +license: +- GPL-2.0-or-later + +# The path to the license file for the collection. This path is relative to the root of the collection. This key is +# mutually exclusive with 'license' +license_file: '' + +# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character +# requirements as 'namespace' and 'name' +tags: [] + +# Collections that this collection requires to be installed for it to be usable. The key of the dict is the +# collection label 'namespace.name'. The value is a version range +# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version +# range specifiers can be set and are separated by ',' +dependencies: {} + +# The URL of the originating SCM repository +repository: http://example.com/repository + +# The URL to any online docs +documentation: http://docs.example.com + +# The URL to the homepage of the collection/project +homepage: http://example.com + +# The URL to the collection issue tracker +issues: http://example.com/issue/tracker + +# A list of file glob-like patterns used to filter any files or directories that should not be included in the build +# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This +# uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry', +# and '.git' are always filtered. Mutually exclusive with 'manifest' +build_ignore: [] + +# A dict controlling use of manifest directives used in building the collection artifact. The key 'directives' is a +# list of MANIFEST.in style +# L(directives,https://packaging.python.org/en/latest/guides/using-manifest-in/#manifest-in-commands). The key +# 'omit_default_directives' is a boolean that controls whether the default directives are used. Mutually exclusive +# with 'build_ignore' +# manifest: null + diff --git a/meta/runtime.yml b/meta/runtime.yml new file mode 100644 index 0000000..20f709e --- /dev/null +++ b/meta/runtime.yml @@ -0,0 +1,52 @@ +--- +# Collections must specify a minimum required ansible version to upload +# to galaxy +# requires_ansible: '>=2.9.10' + +# Content that Ansible needs to load from another location or that has +# been deprecated/removed +# plugin_routing: +# action: +# redirected_plugin_name: +# redirect: ns.col.new_location +# deprecated_plugin_name: +# deprecation: +# removal_version: "4.0.0" +# warning_text: | +# See the porting guide on how to update your playbook to +# use ns.col.another_plugin instead. +# removed_plugin_name: +# tombstone: +# removal_version: "2.0.0" +# warning_text: | +# See the porting guide on how to update your playbook to +# use ns.col.another_plugin instead. +# become: +# cache: +# callback: +# cliconf: +# connection: +# doc_fragments: +# filter: +# httpapi: +# inventory: +# lookup: +# module_utils: +# modules: +# netconf: +# shell: +# strategy: +# terminal: +# test: +# vars: + +# Python import statements that Ansible needs to load from another location +# import_redirection: +# ansible_collections.ns.col.plugins.module_utils.old_location: +# redirect: ansible_collections.ns.col.plugins.module_utils.new_location + +# Groups of actions/modules that take a common set of options +# action_groups: +# group_name: +# - module1 +# - module2 diff --git a/plugins/README.md b/plugins/README.md new file mode 100644 index 0000000..67a66d4 --- /dev/null +++ b/plugins/README.md @@ -0,0 +1,31 @@ +# Collections Plugins Directory + +This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that +is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that +would contain module utils and modules respectively. + +Here is an example directory of the majority of plugins currently supported by Ansible: + +``` +└── plugins + ├── action + ├── become + ├── cache + ├── callback + ├── cliconf + ├── connection + ├── filter + ├── httpapi + ├── inventory + ├── lookup + ├── module_utils + ├── modules + ├── netconf + ├── shell + ├── strategy + ├── terminal + ├── test + └── vars +``` + +A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible-core/2.16/plugins/plugins.html). diff --git a/.gitattributes b/roles/ansible_slub_awxdemo01/.gitattributes similarity index 100% rename from .gitattributes rename to roles/ansible_slub_awxdemo01/.gitattributes diff --git a/.githooks/pre-commit b/roles/ansible_slub_awxdemo01/.githooks/pre-commit similarity index 100% rename from .githooks/pre-commit rename to roles/ansible_slub_awxdemo01/.githooks/pre-commit diff --git a/.gitignore b/roles/ansible_slub_awxdemo01/.gitignore similarity index 100% rename from .gitignore rename to roles/ansible_slub_awxdemo01/.gitignore diff --git a/.yamllint b/roles/ansible_slub_awxdemo01/.yamllint similarity index 100% rename from .yamllint rename to roles/ansible_slub_awxdemo01/.yamllint diff --git a/LICENSE b/roles/ansible_slub_awxdemo01/LICENSE similarity index 100% rename from LICENSE rename to roles/ansible_slub_awxdemo01/LICENSE diff --git a/roles/ansible_slub_awxdemo01/README.md b/roles/ansible_slub_awxdemo01/README.md new file mode 100644 index 0000000..d6e59a2 --- /dev/null +++ b/roles/ansible_slub_awxdemo01/README.md @@ -0,0 +1,82 @@ +# Ansible-Role "ansible_slub_awxdemo01" + +## Description + +AWX Demo role (read-only tasks to show off). + +## Prerequisites + +To use this role, the following software must be installed on your workstation: +* ansible + +To deploy this role to a managed host, the following software must be installed on the target: +* Python3 +* SSHd + +It is recommended to use Debian VMs as deployed by SLUB's UDA tool with this role. Otherwise you will not have access to the software packages that are located in SLUB's private Debian package repository. + +## Quick Start + +``` + ansible-playbook site.yml [--limit <HOSTNAME>] [-u <USERNAME>] +``` + +## General Ansible usage + +Most options already have sensible defaults in `ansible.cfg`. However, you can override these defaults using CLI options/flags if you want to. + +To simply run the playbook, just call the `site.yml` playbook like this: +``` + ansible-playbook site.yml -u <username> +``` + +If you want to limit the execution to a subset of all hosts that are listed in the inventory, use the `-l` or `--limit` option like this: +``` + ansible-playbook site.yml -l <hostna*> + ansible-playbook site.yml -l <hostname> + ansible-playbook site.yml -l <hostname1>:<hostname2>:... + ansible-playbook site.yml -l <inventory_group> + ansible-playbook site.yml --limit=<hostna*> +``` + +If you do not have Vault password files in the directory above the role direcory, you have to give the Vault password before execution: +``` + ansible-playbook site.yml --ask-vault-pass +``` + +You can use your own inventory file by adding the `-i` or `--inventory=INVENTORY` option: +``` + ansible-playbook site.yml -i inventory.yml + ansible-playbook site.yml --inventory=inventory.yml +``` + +Tasks in this role have been tagged to enable users to only run subsets of tasks. This can be leveraged to decrease run times or run only certain tasks after small changes. +To list all available tags, use: +``` + ansible-playbook site.yml --list-tags +``` +You can then run only certain tagged tasks by using the `--tags` option: +``` + ansible-playbook site.yml -t tag1,tag2,...,tagN + ansible-playbook site.yml --tags=tag1,tag2,...,tagN +``` + +For more help with ansible-playbook, use the `--help` flag. + +## Testing the role + +The test framework has been prepared using the Molecule framework. The details on using the test suite are described below `molecule/`. + +## Variables + +Some variables have been "hidden" in encrypted Ansible Vaults. For security reasons, these Vaults are maintained in a separate private internal repository of SLUB's Git. However, in order to better understand the data within the vaults, you can find `\*.vault.example` files below the `vars/` directory. + +If you work outside of SLUBArchiv and have no access to the vault repository, make sure to put the necessary vaults in the expected paths at `../ansible_vaults/<ROLENAME>/`, as that's where this role expects to find them. + +## git configuration + +Just run the `setup_gitconfig.sh` script that comes with the repo to correctly setup all necessary local Git configurations. + +## Author Information + +If you have any comments or find bugs, please contact Joerg.Sachse@slub-dresden.de, open an issue or open a pull request. diff --git a/ansible.cfg b/roles/ansible_slub_awxdemo01/ansible.cfg similarity index 100% rename from ansible.cfg rename to roles/ansible_slub_awxdemo01/ansible.cfg diff --git a/defaults/main.yml b/roles/ansible_slub_awxdemo01/defaults/main.yml similarity index 100% rename from defaults/main.yml rename to roles/ansible_slub_awxdemo01/defaults/main.yml diff --git a/handlers/main.yml b/roles/ansible_slub_awxdemo01/handlers/main.yml similarity index 100% rename from handlers/main.yml rename to roles/ansible_slub_awxdemo01/handlers/main.yml diff --git a/meta/main.yml b/roles/ansible_slub_awxdemo01/meta/main.yml similarity index 100% rename from meta/main.yml rename to roles/ansible_slub_awxdemo01/meta/main.yml diff --git a/molecule/default/Dockerfile.j2 b/roles/ansible_slub_awxdemo01/molecule/default/Dockerfile.j2 similarity index 100% rename from molecule/default/Dockerfile.j2 rename to roles/ansible_slub_awxdemo01/molecule/default/Dockerfile.j2 diff --git a/molecule/default/INSTALL.rst b/roles/ansible_slub_awxdemo01/molecule/default/INSTALL.rst similarity index 100% rename from molecule/default/INSTALL.rst rename to roles/ansible_slub_awxdemo01/molecule/default/INSTALL.rst diff --git a/molecule/default/molecule.yml b/roles/ansible_slub_awxdemo01/molecule/default/molecule.yml similarity index 100% rename from molecule/default/molecule.yml rename to roles/ansible_slub_awxdemo01/molecule/default/molecule.yml diff --git a/molecule/default/playbook.yml b/roles/ansible_slub_awxdemo01/molecule/default/playbook.yml similarity index 100% rename from molecule/default/playbook.yml rename to roles/ansible_slub_awxdemo01/molecule/default/playbook.yml diff --git a/molecule/default/tests/test_default.py b/roles/ansible_slub_awxdemo01/molecule/default/tests/test_default.py similarity index 100% rename from molecule/default/tests/test_default.py rename to roles/ansible_slub_awxdemo01/molecule/default/tests/test_default.py diff --git a/setup_gitconfig.sh b/roles/ansible_slub_awxdemo01/setup_gitconfig.sh similarity index 100% rename from setup_gitconfig.sh rename to roles/ansible_slub_awxdemo01/setup_gitconfig.sh diff --git a/site.yml b/roles/ansible_slub_awxdemo01/site.yml similarity index 100% rename from site.yml rename to roles/ansible_slub_awxdemo01/site.yml diff --git a/tasks/main.yml b/roles/ansible_slub_awxdemo01/tasks/main.yml similarity index 100% rename from tasks/main.yml rename to roles/ansible_slub_awxdemo01/tasks/main.yml diff --git a/vars/main.yml b/roles/ansible_slub_awxdemo01/vars/main.yml similarity index 100% rename from vars/main.yml rename to roles/ansible_slub_awxdemo01/vars/main.yml -- GitLab