From 3bc922a42a0d6ba4bc02830e550673f02957b490 Mon Sep 17 00:00:00 2001 From: Niall Byrne <9848926+niall-byrne@users.noreply.github.com> Date: Mon, 27 Feb 2023 13:48:13 -0500 Subject: [PATCH] build(POETRY): upgrade ansible to version 7 series --- README.md | 27 +++++++++--- hooks/post_gen_project.sh | 2 + {{cookiecutter.project_slug}}/meta/main.yml | 44 ++++++++++++++++--- .../molecule/default/molecule.yml | 18 ++++++-- .../molecule/docker1/converge.yml | 3 +- .../molecule/docker1/molecule.yml | 4 +- .../molecule/docker1/verify.yml | 4 +- .../molecule/hostmachine1/converge.yml | 3 +- .../molecule/hostmachine1/molecule.yml | 6 ++- .../molecule/hostmachine1/verify.yml | 4 +- {{cookiecutter.project_slug}}/pyproject.toml | 14 +++--- {{cookiecutter.project_slug}}/tasks/main.yml | 8 +++- {{cookiecutter.project_slug}}/tests/test.yml | 6 ++- 13 files changed, 108 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 01f2e970..b4cb6bad 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # Ansible Workbench -Ansible Role Development Environment. - -(Please see the [cookiecutter documentation](https://cookiecutter.readthedocs.io/) for instructions on how to use this project template.) +[Ansible](https://www.ansible.com/) Role Development Environment. ##### Master Branch (Follows the latest production tag): [![ansible-workbench-self-test](https://github.com/niall-byrne/ansible-workbench/workflows/ansible-workbench-self-test/badge.svg?branch=master)](https://github.com/niall-byrne/ansible-workbench/actions) @@ -12,10 +10,19 @@ Ansible Role Development Environment. ## About -This template generates a development environment for Ansible Roles with a functional CI/CD template for both Travis CI and Github. +This [cookiecutter](https://cookiecutter.readthedocs.io/) template generates a development environment for [Ansible Roles](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html) with comprehensive functional CI/CD for both Travis CI and GitHub Actions. + +[Poetry](https://python-poetry.org/) powers a [Python virtual environment](https://docs.python.org/3/library/venv.html) loaded with [Molecule](https://molecule.readthedocs.io/en/latest/), and [Ansible-Lint](https://ansible-lint.readthedocs.io/) allowing you to develop and test roles with a focus on quality. + +**Windows Users**: +- If you are working locally with Windows, you'll need a Posix or Linux virtual environment of some kind to use this template. +- Neither Ansible, nor Ansible-Lint support this platform. + +**OSX, Linux, BSD Users**: +- Please follow the [Quick Start Guide](#Quick%20Start%20Guide) below. ## Requirements -You'll need [Python](https://www.python.org/) 3.9 or later to use this template. +You'll need [Python](https://www.python.org/) **3.9** or later to use this template. ([Ansible](https://www.ansible.com/) now requires this.) ## Quick Start Guide @@ -24,9 +31,15 @@ You'll need [Python](https://www.python.org/) 3.9 or later to use this template. Give your project a name, and populate the other required template inputs. +(Please read the section on [TOML Linting](#Maintaining%20your%20pyproject.toml%20File) for details on this optional tooling.) + Once the templating is finished: - `cd ` -- `poetry shell` (to interact with ansible and molecule inside a virtualenv) +- `poetry shell` (to interact with [Ansible](https://www.ansible.com/) and [Molecule](https://molecule.readthedocs.io/en/latest/) inside a virtualenv) + +You can then execute commands against the placeholder content: +- `molecule lint` +- `molecule test -s docker1` ## License @@ -80,7 +93,7 @@ The python library [pre-commit](https://pre-commit.com/) comes installed with a Integrations with the following third party services are configured during templating: -- [Github Workflows](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions) +- [GitHub Workflows](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions) - [workflows](./{{cookiecutter.project_slug}}/.github/workflows) - [TravisCI](https://travis-ci.com/) - [.travis.yml](./{{cookiecutter.project_slug}}/.travis.yml) diff --git a/hooks/post_gen_project.sh b/hooks/post_gen_project.sh index 52af4bd6..615ce1ac 100644 --- a/hooks/post_gen_project.sh +++ b/hooks/post_gen_project.sh @@ -10,6 +10,8 @@ # cookiecutter only script. +set -eo pipefail + ANSIBLE_WORKBENCH_BRANCH_NAME_BASE="${ANSIBLE_WORKBENCH_BRANCH_NAME_BASE-"{{ cookiecutter._BRANCH_NAME_BASE }}"}" ANSIBLE_WORKBENCH_BRANCH_NAME_DEVELOPMENT="${ANSIBLE_WORKBENCH_BRANCH_NAME_DEVELOPMENT-"{{ cookiecutter._BRANCH_NAME_DEVELOPMENT }}"}" ANSIBLE_WORKBENCH_TEMPLATE_URL="https://github.com/niall-byrne/ansible-workbench.git" diff --git a/{{cookiecutter.project_slug}}/meta/main.yml b/{{cookiecutter.project_slug}}/meta/main.yml index aa5c367c..3b696218 100644 --- a/{{cookiecutter.project_slug}}/meta/main.yml +++ b/{{cookiecutter.project_slug}}/meta/main.yml @@ -3,16 +3,48 @@ galaxy_info: role_name: {{ cookiecutter.galaxy_role_slug }} namespace: {{ cookiecutter.galaxy_namespace_slug }} author: {{ cookiecutter.author }} + description: {{ cookiecutter.description }} company: {{ cookiecutter.company }} + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 license: MPL-2 + + # An example MPL-2 License is included by default. + + min_ansible_version: "2.1" + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: - - name: MacOSX + - name: Fedora versions: - - '10.15' - - '10.14' - min_ansible_version: 3.3.0 - galaxy_tags: - - osx + - all + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. dependencies: [] diff --git a/{{cookiecutter.project_slug}}/molecule/default/molecule.yml b/{{cookiecutter.project_slug}}/molecule/default/molecule.yml index bf6bdf57..a3ae4ffe 100644 --- a/{{cookiecutter.project_slug}}/molecule/default/molecule.yml +++ b/{{cookiecutter.project_slug}}/molecule/default/molecule.yml @@ -4,15 +4,25 @@ dependency: options: role-file: requirements.yml requirements-file: requirements.yml + timeout: "120" + force: false driver: name: delegated + options: + managed: False + ansible_connection_options: + ansible_connection: local + ansible_sudo_pass: "${ANSIBLE_SUDO_PASSWORD}" +lint: | + set -e + yamllint -f standard . + ansible-lint platforms: - name: instance provisioner: name: ansible + config_options: + privilege_escalation: + become_method: sudo verifier: name: ansible -lint: | - set -e - yamllint -f standard . - ansible-lint diff --git a/{{cookiecutter.project_slug}}/molecule/docker1/converge.yml b/{{cookiecutter.project_slug}}/molecule/docker1/converge.yml index 8b910d74..be717259 100644 --- a/{{cookiecutter.project_slug}}/molecule/docker1/converge.yml +++ b/{{cookiecutter.project_slug}}/molecule/docker1/converge.yml @@ -2,11 +2,10 @@ - name: Converge hosts: all connection: local - vars: tasks: - name: Load Scenario Variables - include_vars: vars/main.yml + ansible.builtin.include_vars: vars/main.yml - name: "Include {{ cookiecutter.galaxy_namespace_slug }}.{{ cookiecutter.galaxy_role_slug }}" ansible.builtin.include_role: name: "{{ cookiecutter.galaxy_namespace_slug }}.{{ cookiecutter.galaxy_role_slug }}" diff --git a/{{cookiecutter.project_slug}}/molecule/docker1/molecule.yml b/{{cookiecutter.project_slug}}/molecule/docker1/molecule.yml index aec43b91..5c494dea 100644 --- a/{{cookiecutter.project_slug}}/molecule/docker1/molecule.yml +++ b/{{cookiecutter.project_slug}}/molecule/docker1/molecule.yml @@ -4,11 +4,13 @@ dependency: options: role-file: requirements.yml requirements-file: requirements.yml + timeout: "120" + force: false driver: name: docker platforms: - name: instance - image: docker.io/pycontribs/centos:8 + image: fedora:latest pre_build_image: true provisioner: name: ansible diff --git a/{{cookiecutter.project_slug}}/molecule/docker1/verify.yml b/{{cookiecutter.project_slug}}/molecule/docker1/verify.yml index d4ef6ad6..ce38e124 100644 --- a/{{cookiecutter.project_slug}}/molecule/docker1/verify.yml +++ b/{{cookiecutter.project_slug}}/molecule/docker1/verify.yml @@ -4,7 +4,7 @@ gather_facts: false tasks: - name: Load Scenario Variables - include_vars: vars/main.yml + ansible.builtin.include_vars: vars/main.yml - name: PlaceHolder Task - debug: + ansible.builtin.debug: msg: "Verification Script." diff --git a/{{cookiecutter.project_slug}}/molecule/hostmachine1/converge.yml b/{{cookiecutter.project_slug}}/molecule/hostmachine1/converge.yml index 2c6bdb2c..be717259 100644 --- a/{{cookiecutter.project_slug}}/molecule/hostmachine1/converge.yml +++ b/{{cookiecutter.project_slug}}/molecule/hostmachine1/converge.yml @@ -2,9 +2,10 @@ - name: Converge hosts: all connection: local + tasks: - name: Load Scenario Variables - include_vars: vars/main.yml + ansible.builtin.include_vars: vars/main.yml - name: "Include {{ cookiecutter.galaxy_namespace_slug }}.{{ cookiecutter.galaxy_role_slug }}" ansible.builtin.include_role: name: "{{ cookiecutter.galaxy_namespace_slug }}.{{ cookiecutter.galaxy_role_slug }}" diff --git a/{{cookiecutter.project_slug}}/molecule/hostmachine1/molecule.yml b/{{cookiecutter.project_slug}}/molecule/hostmachine1/molecule.yml index 709d32d7..6e6a6cf9 100644 --- a/{{cookiecutter.project_slug}}/molecule/hostmachine1/molecule.yml +++ b/{{cookiecutter.project_slug}}/molecule/hostmachine1/molecule.yml @@ -4,6 +4,8 @@ dependency: options: role-file: requirements.yml requirements-file: requirements.yml + timeout: "120" + force: false driver: name: delegated options: @@ -11,10 +13,12 @@ driver: ansible_connection_options: ansible_connection: local ansible_sudo_pass: "${ANSIBLE_SUDO_PASSWORD}" - become_method: sudo platforms: - name: instance provisioner: name: ansible + config_options: + privilege_escalation: + become_method: sudo verifier: name: ansible diff --git a/{{cookiecutter.project_slug}}/molecule/hostmachine1/verify.yml b/{{cookiecutter.project_slug}}/molecule/hostmachine1/verify.yml index d4ef6ad6..ce38e124 100644 --- a/{{cookiecutter.project_slug}}/molecule/hostmachine1/verify.yml +++ b/{{cookiecutter.project_slug}}/molecule/hostmachine1/verify.yml @@ -4,7 +4,7 @@ gather_facts: false tasks: - name: Load Scenario Variables - include_vars: vars/main.yml + ansible.builtin.include_vars: vars/main.yml - name: PlaceHolder Task - debug: + ansible.builtin.debug: msg: "Verification Script." diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index a4982846..2d466daf 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -15,13 +15,15 @@ python = ">={{ cookiecutter._GITHUB_CI_PYTHON_VERSIONS | first }}.0,<4.0" [tool.poetry.dev-dependencies] - ansible = "^5.2.0" - ansible-compat = "<2.1.0" - ansible-lint = "^5.3.2" - commitizen = "^2.20.4" + ansible = "^7.2.0" + commitizen = "^2.42.0" pre-commit = "^3.1.0" - yamllint = "^1.26.3" + yamllint = "^1.29.0" + + [tool.poetry.dev-dependencies.ansible-lint] + markers = "platform_system != 'Windows'" + version = "^6.12.2" [tool.poetry.dev-dependencies.molecule] extras = ["docker"] - version = "^3.5.2" + version = "^4.0.0" diff --git a/{{cookiecutter.project_slug}}/tasks/main.yml b/{{cookiecutter.project_slug}}/tasks/main.yml index d5ee50c6..283e157b 100644 --- a/{{cookiecutter.project_slug}}/tasks/main.yml +++ b/{{cookiecutter.project_slug}}/tasks/main.yml @@ -2,4 +2,10 @@ # tasks file for {{ cookiecutter.project_slug }} - name: Placeholder Task - debug: msg="Your dedication and hard work goes here." + ansible.builtin.debug: + msg: "Your dedication and hard work goes here." + +- name: Placeholder Task With Priviledge + become: true + ansible.builtin.command: whoami + changed_when: false diff --git a/{{cookiecutter.project_slug}}/tests/test.yml b/{{cookiecutter.project_slug}}/tests/test.yml index 1ed1af27..ef38c06d 100644 --- a/{{cookiecutter.project_slug}}/tests/test.yml +++ b/{{cookiecutter.project_slug}}/tests/test.yml @@ -1,5 +1,7 @@ --- -- hosts: localhost +- name: Default test for {{ cookiecutter.galaxy_namespace_slug }}.{{ cookiecutter.galaxy_role_slug }} + hosts: localhost remote_user: root + roles: - - {{ cookiecutter.project_slug }} + - {{ cookiecutter.galaxy_namespace_slug }}.{{ cookiecutter.galaxy_role_slug }}