From 883d8ab13cb2a6e6f2e85b84b5221aa5057f25be Mon Sep 17 00:00:00 2001 From: Cybercinch Solutions Date: Thu, 22 Aug 2024 15:08:47 +1200 Subject: [PATCH] Initial commit --- .ansible-lint | 6 ++ .github/workflows/CI.yml | 104 ++++++++++++++++++++++++++++++++++ .gitignore | 2 + README.md | 39 +++++++++++++ defaults/main.yml | 2 + handlers/main.yml | 2 + justfile | 3 + meta/main.yml | 54 ++++++++++++++++++ molecule/default/converge.yml | 8 +++ molecule/default/create.yml | 35 ++++++++++++ molecule/default/destroy.yml | 24 ++++++++ molecule/default/molecule.yml | 19 +++++++ requirements.txt | 6 ++ scripts/rename.sh | 29 ++++++++++ tasks/main.yml | 2 + vars/main.yml | 2 + 16 files changed, 337 insertions(+) create mode 100644 .ansible-lint create mode 100644 .github/workflows/CI.yml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 justfile create mode 100644 meta/main.yml create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/create.yml create mode 100644 molecule/default/destroy.yml create mode 100644 molecule/default/molecule.yml create mode 100644 requirements.txt create mode 100755 scripts/rename.sh create mode 100644 tasks/main.yml create mode 100644 vars/main.yml diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..7a55960 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,6 @@ +profile: basic + +skip_list: # or 'skip_list' to silence them completely + - experimental # all rules tagged as experimental + - unnamed-task # All tasks should be named + - fqcn-builtins diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..f7c036f --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,104 @@ +--- +name: CI +on: + push: + branches: + - "**" + tags: + - "!**" + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + cache: 'pip' # caching pip dependencies + + - name: Ensure requirements are installed + run: pip install -r requirements.txt + + - name: Lint with ansible-lint + run: ansible-lint --exclude ./tests -c ".ansible-lint" + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + - name: Lint with yamllint + run: yamllint . + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + molecule: + name: Molecule Test + runs-on: ubuntu-latest + needs: lint + strategy: + fail-fast: true + matrix: + os: [almalinux8, almalinux9] + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + cache: 'pip' # caching pip dependencies + - name: Ensure requirements are installed + run: pip install -r requirements.txt + - name: Run Molecule tests. + run: molecule test + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + MOLECULE_DISTRO: ${{ matrix.os }} + release: + runs-on: ubuntu-latest + needs: + - lint + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '1.22' + - run: | + echo "github repo: ${GITHUB_REPOSITORY}" + echo "env vars: $(env)" + - uses: go-semantic-release/action@v1 + with: + custom-arguments: --provider=gitea + env: + GITEA_TOKEN: ${{ secrets.G_TOKEN }} + GITEA_HOST: ${{ secrets.G_SERVER_URL}} + notify: + runs-on: ubuntu-latest + needs: + - lint + - release + steps: + - name: ntfy-success-notifications + uses: niniyas/ntfy-action@master + if: success() + with: + url: '${{ vars.NTFY_URL }}' + title: Workflow success for ${GITHUB_REPOSITORY} + topic: 'ci-status' + priority: 4 + tags: +1,partying_face,action,successfully,completed + details: Workflow has been successfully completed! + icon: 'https://styles.redditmedia.com/t5_32uhe/styles/communityIcon_xnt6chtnr2j21.png' + image: true + + - name: ntfy-failed-notifications + uses: niniyas/ntfy-action@master + if: failure() + with: + url: '${{ vars.NTFY_URL }}' + title: Workflow failed for ${GITHUB_REPOSITORY} + topic: 'ci-status' + priority: 5 + tags: -1,skull,action,failed + details: Workflow has failed! + actions: 'default' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c728427 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/*.bak + diff --git a/README.md b/README.md new file mode 100644 index 0000000..384f0da --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +%role_name% +========= + +%role_description% + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ +%author_name% + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..3e0786f --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for template_role diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..1797976 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for template_role diff --git a/justfile b/justfile new file mode 100644 index 0000000..4ed0895 --- /dev/null +++ b/justfile @@ -0,0 +1,3 @@ + +rename: + @scripts/rename.sh diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..ee2adad --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,54 @@ +galaxy_info: + author: %author_name% + role_name: %role_name% + description: %role_description% + company: %company_name% + namespace: %namespace% + + # 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: license (GPL-2.0-or-later, MIT, etc) + + 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: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + 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: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..e600756 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,8 @@ +--- +- name: Converge + hosts: all + gather_facts: false + tasks: + - name: Replace this task with one that validates your content + ansible.builtin.debug: + msg: "This is the effective test" diff --git a/molecule/default/create.yml b/molecule/default/create.yml new file mode 100644 index 0000000..fcd6b92 --- /dev/null +++ b/molecule/default/create.yml @@ -0,0 +1,35 @@ +--- +- name: Create + hosts: localhost + connection: local + gather_facts: false + # no_log: "{{ molecule_no_log }}" + tasks: + # TODO: Developer must implement and populate 'server' variable + + - name: Create instance config + when: server.changed | default(false) | bool # noqa no-handler + block: + - name: Populate instance config dict # noqa jinja + ansible.builtin.set_fact: + instance_conf_dict: {} + # instance': "{{ }}", + # address': "{{ }}", + # user': "{{ }}", + # port': "{{ }}", + # 'identity_file': "{{ }}", } + with_items: "{{ server.results }}" + register: instance_config_dict + + - name: Convert instance config dict to a list + ansible.builtin.set_fact: + instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}" + + - name: Dump instance config + ansible.builtin.copy: + content: | + # Molecule managed + + {{ instance_conf | to_json | from_json | to_yaml }} + dest: "{{ molecule_instance_config }}" + mode: "0600" diff --git a/molecule/default/destroy.yml b/molecule/default/destroy.yml new file mode 100644 index 0000000..59d6a8e --- /dev/null +++ b/molecule/default/destroy.yml @@ -0,0 +1,24 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: false + # no_log: "{{ molecule_no_log }}" + tasks: + # Developer must implement. + + # Mandatory configuration for Molecule to function. + + - name: Populate instance config + ansible.builtin.set_fact: + instance_conf: {} + + - name: Dump instance config + ansible.builtin.copy: + content: | + # Molecule managed + + {{ instance_conf | to_json | from_json | to_yaml }} + dest: "{{ molecule_instance_config }}" + mode: "0600" + when: server.changed | default(false) | bool # noqa no-handler diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..c539fb6 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,19 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: molecule-${MOLECULE_DISTRO:-almalinux8} + image: "cybercinch/docker-${MOLECULE_DISTRO:-almalinux8}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + cgroupns_mode: host + privileged: true + pre_build_image: true +provisioner: + name: ansible + env: + MOLECULE_NO_LOG: true + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..41f9900 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +ansible-core<2.17 +ansible-compat >= 4 +molecule[docker]== 24.2.1 +ansible-lint==24.2.2 +yamllint==1.35.1 +passlib==1.7.4 diff --git a/scripts/rename.sh b/scripts/rename.sh new file mode 100755 index 0000000..a744d6e --- /dev/null +++ b/scripts/rename.sh @@ -0,0 +1,29 @@ + +#!/bin/bash +# Ask the user for their name +echo What is your name? e.g Joe Bloggs +read varname +echo What is your Company/Org name? +read varorg +echo What is this roles name? +read varrolename +echo Please enter a description for this role +read vardesc +echo What is your galaxy namespace? e.g cybercinch +read varnamespace +echo -n "Updating role information..." +sed -i -e "s/%author_name%/${varname}/g" \ + -e "s/%role_description%/${vardesc}/g" \ + -e "s/%company_name%/${varorg}/g" \ + -e "s/%role_name%/${varrolename}/g" \ + -e "s/%namespace%/${varnamespace}/g" \ +meta/main.yml + +sed -i -e "s/%author_name%/${varname}/g" \ + -e "s/%role_name%/${varrolename}/g" \ +README.md +echo "done" + +echo "Now finish any remaining changes in meta/main.yml and README.md" +echo "Once that is completed commit and happy developing!" + diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..a3588e7 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks file for template_role diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..f01bf99 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for template_role