From c0c54c57421c2e6ed76b4f21dee15cad7b702f92 Mon Sep 17 00:00:00 2001 From: James Bennett <jwbennet@gmail.com> Date: Tue, 27 Feb 2024 04:55:03 +0000 Subject: [PATCH] feat: Ansible project support Adds support for generating a project which will use Ansible. Creates a base inventory, playbook, and installs the necessary tooling for working within the Ansible ecosystem. --- ansible/.devcontainer/devcontainer.json.jinja | 1 + ansible/.editorconfig | 1 + ansible/CHANGELOG.md.jinja | 1 + ansible/Taskfile.yaml.jinja | 34 +++++++++++++++++++ ansible/ansible.cfg | 2 ++ ansible/inventory.yaml | 5 +++ ansible/main.yaml | 7 ++++ ansible/requirements.yaml | 7 ++++ ansible/version.txt.jinja | 1 + .../.commitlintrc | 1 + .../.devcontainer/devcontainer.json.jinja | 12 +++++++ .../.lintstagedrc | 1 + .../.mkdocsrc.jinja | 1 + .../.precommitrc | 1 + .../.prettierrc | 1 + .../renovate.json.jinja | 1 + .../devcontainer-build-and-push.yaml.jinja | 1 + .../workflows/release-please.yaml.jinja | 1 + .../workflows/renovate.yaml.jinja | 1 + copier.yaml | 1 + 20 files changed, 81 insertions(+) create mode 120000 ansible/.devcontainer/devcontainer.json.jinja create mode 120000 ansible/.editorconfig create mode 120000 ansible/CHANGELOG.md.jinja create mode 100644 ansible/Taskfile.yaml.jinja create mode 100644 ansible/ansible.cfg create mode 100644 ansible/inventory.yaml create mode 100644 ansible/main.yaml create mode 100644 ansible/requirements.yaml create mode 120000 ansible/version.txt.jinja create mode 120000 ansible/{% if git_provider == 'github' %}.github{% endif %}/.commitlintrc create mode 100644 ansible/{% if git_provider == 'github' %}.github{% endif %}/.devcontainer/devcontainer.json.jinja create mode 120000 ansible/{% if git_provider == 'github' %}.github{% endif %}/.lintstagedrc create mode 120000 ansible/{% if git_provider == 'github' %}.github{% endif %}/.mkdocsrc.jinja create mode 120000 ansible/{% if git_provider == 'github' %}.github{% endif %}/.precommitrc create mode 120000 ansible/{% if git_provider == 'github' %}.github{% endif %}/.prettierrc create mode 120000 ansible/{% if git_provider == 'github' %}.github{% endif %}/renovate.json.jinja create mode 120000 ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/devcontainer-build-and-push.yaml.jinja create mode 120000 ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/release-please.yaml.jinja create mode 120000 ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/renovate.yaml.jinja diff --git a/ansible/.devcontainer/devcontainer.json.jinja b/ansible/.devcontainer/devcontainer.json.jinja new file mode 120000 index 0000000..f3733b0 --- /dev/null +++ b/ansible/.devcontainer/devcontainer.json.jinja @@ -0,0 +1 @@ +../../generic/.devcontainer/devcontainer.json.jinja \ No newline at end of file diff --git a/ansible/.editorconfig b/ansible/.editorconfig new file mode 120000 index 0000000..a7109bc --- /dev/null +++ b/ansible/.editorconfig @@ -0,0 +1 @@ +../generic/.editorconfig \ No newline at end of file diff --git a/ansible/CHANGELOG.md.jinja b/ansible/CHANGELOG.md.jinja new file mode 120000 index 0000000..3cc3f6f --- /dev/null +++ b/ansible/CHANGELOG.md.jinja @@ -0,0 +1 @@ +../generic/CHANGELOG.md.jinja \ No newline at end of file diff --git a/ansible/Taskfile.yaml.jinja b/ansible/Taskfile.yaml.jinja new file mode 100644 index 0000000..66908ef --- /dev/null +++ b/ansible/Taskfile.yaml.jinja @@ -0,0 +1,34 @@ +version: "3" + +tasks: + docs: + desc: Start a server which serves the project documentation + cmds: + - mkdocs serve {% if git_provider == 'github' %}--config-file=.github/.mkdocsrc{% endif %} + inventory: + desc: Display the inventory as seen from Ansible in graph form + cmds: + - ansible-inventory --graph + inventory-list: + desc: Display the inventory as seen from Ansible in list form + cmds: + - ansible-inventory --list + lint: + desc: Check the syntax of Ansible playbooks + cmds: + - ansible-lint + run: + desc: Run playbook + cmds: + - ansible-playbook main.yaml + setup: + desc: Install dependencies and setup the project + cmds: + - pre-commit install {%- if git_provider == 'github' %} --config .github/.precommitrc{% endif %} --hook-type pre-commit --hook-type commit-msg + - pip install --user ansible-lint + - ansible-galaxy install -r requirements.yaml + default: + cmds: + - task --list + +silent: true diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..3f05714 --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +inventory = ./inventory.yaml diff --git a/ansible/inventory.yaml b/ansible/inventory.yaml new file mode 100644 index 0000000..b0f6507 --- /dev/null +++ b/ansible/inventory.yaml @@ -0,0 +1,5 @@ +--- +ungrouped: + hosts: + localhost: + ansible_connection: local diff --git a/ansible/main.yaml b/ansible/main.yaml new file mode 100644 index 0000000..d74a028 --- /dev/null +++ b/ansible/main.yaml @@ -0,0 +1,7 @@ +--- +- name: Demo Playbook + hosts: all + tasks: + - name: Debug information + ansible.builtin.debug: + msg: "The hostname is {{ ansible_hostname }}" diff --git a/ansible/requirements.yaml b/ansible/requirements.yaml new file mode 100644 index 0000000..03c40c6 --- /dev/null +++ b/ansible/requirements.yaml @@ -0,0 +1,7 @@ +--- +collections: + - name: ansible.utils + version: 3.0.0 +# roles: +# - name: TBD +# version: TBD diff --git a/ansible/version.txt.jinja b/ansible/version.txt.jinja new file mode 120000 index 0000000..aa1d710 --- /dev/null +++ b/ansible/version.txt.jinja @@ -0,0 +1 @@ +../generic/version.txt.jinja \ No newline at end of file diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/.commitlintrc b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.commitlintrc new file mode 120000 index 0000000..3335227 --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.commitlintrc @@ -0,0 +1 @@ +../../generic/{% if git_provider == 'github' %}.github{% endif %}/.commitlintrc \ No newline at end of file diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/.devcontainer/devcontainer.json.jinja b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.devcontainer/devcontainer.json.jinja new file mode 100644 index 0000000..2386f50 --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.devcontainer/devcontainer.json.jinja @@ -0,0 +1,12 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +{ + "name": "{{project_name}}", + "image": "ghcr.io/jwbennet/project-base-dev-container:2.2.0", + "features": { + // renovate: depType=devcontainerFeature datasource=docker + "ghcr.io/devcontainers-contrib/features/ansible:2.0.17": { + // renovate: depType=devDependencies datasource=github-tags depName=ansible/ansible extractVersion=true + "version": "2.16.3" + } + } +} diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/.lintstagedrc b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.lintstagedrc new file mode 120000 index 0000000..6a4903e --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.lintstagedrc @@ -0,0 +1 @@ +../../generic/{% if git_provider == 'github' %}.github{% endif %}/.lintstagedrc \ No newline at end of file diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/.mkdocsrc.jinja b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.mkdocsrc.jinja new file mode 120000 index 0000000..580092f --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.mkdocsrc.jinja @@ -0,0 +1 @@ +../../generic/{% if git_provider == 'github' %}.github{% endif %}/.mkdocsrc.jinja \ No newline at end of file diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/.precommitrc b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.precommitrc new file mode 120000 index 0000000..60946f1 --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.precommitrc @@ -0,0 +1 @@ +../../generic/{% if git_provider == 'github' %}.github{% endif %}/.precommitrc \ No newline at end of file diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/.prettierrc b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.prettierrc new file mode 120000 index 0000000..1ae0676 --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/.prettierrc @@ -0,0 +1 @@ +../../generic/{% if git_provider == 'github' %}.github{% endif %}/.prettierrc \ No newline at end of file diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/renovate.json.jinja b/ansible/{% if git_provider == 'github' %}.github{% endif %}/renovate.json.jinja new file mode 120000 index 0000000..1218147 --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/renovate.json.jinja @@ -0,0 +1 @@ +../../generic/{% if git_provider == 'github' %}.github{% endif %}/renovate.json.jinja \ No newline at end of file diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/devcontainer-build-and-push.yaml.jinja b/ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/devcontainer-build-and-push.yaml.jinja new file mode 120000 index 0000000..feeb526 --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/devcontainer-build-and-push.yaml.jinja @@ -0,0 +1 @@ +../../../generic/{% if git_provider == 'github' %}.github{% endif %}/workflows/devcontainer-build-and-push.yaml.jinja \ No newline at end of file diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/release-please.yaml.jinja b/ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/release-please.yaml.jinja new file mode 120000 index 0000000..947e851 --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/release-please.yaml.jinja @@ -0,0 +1 @@ +../../../generic/{% if git_provider == 'github' %}.github{% endif %}/workflows/release-please.yaml.jinja \ No newline at end of file diff --git a/ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/renovate.yaml.jinja b/ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/renovate.yaml.jinja new file mode 120000 index 0000000..3f977d6 --- /dev/null +++ b/ansible/{% if git_provider == 'github' %}.github{% endif %}/workflows/renovate.yaml.jinja @@ -0,0 +1 @@ +../../../generic/{% if git_provider == 'github' %}.github{% endif %}/workflows/renovate.yaml.jinja \ No newline at end of file diff --git a/copier.yaml b/copier.yaml index 4de690c..854dc15 100644 --- a/copier.yaml +++ b/copier.yaml @@ -6,6 +6,7 @@ project_type: type: str help: Which type of project to copy? choices: + Ansible: ansible Generic: generic default: generic custom_devcontainer_features: