commit fc4ce8359c943d9722831b5d26854669be50c361 Author: Louis Abel Date: Fri Dec 18 15:55:55 2020 -0700 Initial commit diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..a998c16 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,5 @@ +warn_list: + - '204' # Lines should be less than 160 characters + - '701' # meta/main.yml should contain relevant info +skip_list: + - '106' # Role name must match ^[a-z][a-z0-9_]+$ pattern diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0076f88 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.3.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-json + - id: pretty-format-json + + + - repo: local + hooks: + - id: ansible-lint + name: Ansible-lint + description: This hook runs ansible-lint. + entry: ansible-lint --force-color + language: python + # do not pass files to ansible-lint, see: + # https://github.com/ansible/ansible-lint/issues/611 + pass_filenames: false + always_run: true + + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.24.2 + hooks: + - id: yamllint + files: \.(yaml|yml)$ + types: [file, yaml] + entry: yamllint diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..4a8ae86 --- /dev/null +++ b/.yamllint @@ -0,0 +1,11 @@ +--- +extends: default + +rules: + line-length: + max: 140 + level: warning + +ignore: | + .travis.yml + .github diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..60554f6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] +- what do we need to do + +## [0.0.1] - 2020-12-13 +### Added +- Initial + +### Changed +- None + +### Removed +- None diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9bcc52f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Darkbat91 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..13ffe68 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +CI Badge + +# Ansible template role +basic Role to use going forward because I forget pieces + +## Getting started +Ensure all dependencies are installed and then follow the below process +1. `git clone repo` Get the development repository +2. `pre-commit install` Install the pre-commit hooks +3. Make edits as explained in the customization section +4. `pre-commit` Make sure existing code is good +5. `do development` Dont ask me :D +6. `pre-commit` Make sure the edits are good to go +7. `molecule converge` + +## Dependencies +This repo expects 3 things installed on the local machine +1. [pre-commit](https://pre-commit.com/) Methodology to test yaml style +2. [ansible-lint](https://github.com/ansible-community/ansible-lint) lint ansible code for best practices +3. [yamllint](https://github.com/adrienverge/yamllint) Ensures all yaml is well formed + +### Customization +There are a few files that are required to be updated when using this template +1. [molecule/requirements.yml](molecule/requirements.yml) - Update with any required roles or collections +2. [molecule/default/converge.yml](molecule/default/converge.yml) - update with new role name +3. [molecule/default/molecule.yml](molecule/default/molecule.yml) - update with desired distributions and extra playbooks +4. [github](github) - Rename to `.github` and push, this will set up yamllint, ansible-lint and a CI check job for the `main` branch + 1. NOTE: If you are using a SAML token this may fail. You can created the files within the Github web app + +### Optional +The github actions are configured to automatically run the molecule tests but if you want to load them locally you will also need molecule installed on the development machine + +## Advanced + +There are numerous other options within the [defaults/main.yml](./defaults/main.yml) that can change other parts of the behavior of the system + +## Changelog +The [changelog](./CHANGELOG.md) is stored externally + + diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..7faaf71 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# ansible default variables - most variables live here \ No newline at end of file diff --git a/github/workflows/ansible-lint.yml b/github/workflows/ansible-lint.yml new file mode 100644 index 0000000..9b4c497 --- /dev/null +++ b/github/workflows/ansible-lint.yml @@ -0,0 +1,33 @@ +--- +# https://github.com/ansible/ansible-lint-action +name: Ansible Lint + +on: + push: + paths: + - '**.yml' + - '**.yaml' + +jobs: + ansible-lint: + runs-on: ubuntu-latest + timeout-minutes: 7 + + steps: + - name: Git checkout + uses: actions/checkout@v2 + + - name: Add installed collections in Ansible configuration + run: | + echo '[defaults]' > ansible.cfg + echo 'collections_paths = ./collections' >> ansible.cfg + - name: Install role requirements + run: ansible-galaxy role install -r molecule/requirements.yml +# TODO: Figure out how to get this not to error so this action is universal +# - name: Install collection requirements +# run: ansible-galaxy collection install -r molecule/requirements.yml + + - name: Ansible Lint + uses: rocky-linux/ansible-lint-action@master + with: + args: "--exclude .github" diff --git a/github/workflows/main.yml b/github/workflows/main.yml new file mode 100644 index 0000000..848874e --- /dev/null +++ b/github/workflows/main.yml @@ -0,0 +1,39 @@ +--- +name: CI + +'on': + pull_request: + push: + branches: + - main + schedule: + - cron: "30 6 * * 2" + +jobs: + molecule: + name: Molecule + runs-on: ubuntu-latest + strategy: + matrix: + include: + - distro: centos7 + playbook: converge.yml + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + + - name: Set up Python 3. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies. + run: pip3 install ansible molecule[docker] docker + + - name: Run Molecule tests. + run: molecule test + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + MOLECULE_DISTRO: ${{ matrix.distro }} + MOLECULE_PLAYBOOK: ${{ matrix.playbook }} diff --git a/github/workflows/yaml-lint.yml b/github/workflows/yaml-lint.yml new file mode 100644 index 0000000..0af0a62 --- /dev/null +++ b/github/workflows/yaml-lint.yml @@ -0,0 +1,21 @@ +--- +# https://github.com/ibiqlik/action-yamllint +name: YAML Lint + +on: + push: + paths: + - '**.yml' + - '**.yaml' + +jobs: + yamllint: + runs-on: ubuntu-latest + timeout-minutes: 1 + + steps: + - name: Git checkout + uses: actions/checkout@v2 + + - name: yamllint + uses: ibiqlik/action-yamllint@v3 diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..568c597 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,53 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # 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: MIT + + min_ansible_version: 2.8 + + # 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. + \ No newline at end of file diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..e3de332 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,13 @@ +--- +- name: Converge + hosts: all + become: true + + pre_tasks: + - name: Update apt cache. + apt: update_cache=true cache_valid_time=600 + when: ansible_os_family == 'Debian' + changed_when: false + + roles: + - role: ansible-role-mycoolrole diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..ce89169 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,26 @@ +--- +dependency: + name: galaxy + options: + ignore-certs: true + role-file: molecule/requirements.yml + +driver: + name: docker + +# lint: | +# set -e +# yamllint . +# ansible-lint +platforms: + - name: instance + image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible + playbooks: + converge: ${MOLECULE_PLAYBOOK:-converge.yml} diff --git a/molecule/requirements.yml b/molecule/requirements.yml new file mode 100644 index 0000000..4d08b50 --- /dev/null +++ b/molecule/requirements.yml @@ -0,0 +1,3 @@ +--- +roles: + ## Deps go here Should be very short and only if Absolutely needed diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..2583e53 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,2 @@ +--- +# tasks \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..0d75ed2 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,3 @@ +--- +# vars file - Nothing should really go here but dynamic imports +# and truely static items \ No newline at end of file