Skip to content

Commit

Permalink
Merge pull request #13 from wayofdev/feat-update-tpl
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp authored Jun 29, 2022
2 parents 6ff588a + 85ab883 commit 88322cb
Show file tree
Hide file tree
Showing 41 changed files with 1,557 additions and 593 deletions.
6 changes: 6 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ skip_list:
- command-instead-of-shell
- risky-shell-pipe
- line-length

exclude_paths:
- ./contrib
- ./.venv

...
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.{yml,yaml,toml}]
[*.{yml,yaml,toml,py}]
indent_size = 2
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

github: wayofdev

...
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ updates:
directory: "/"
schedule:
interval: "daily"

...
67 changes: 48 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,89 @@ jobs:
- name: Check out the codebase
uses: actions/checkout@v3

- name: Set up Python 3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install Poetry
- name: Install poetry into system
uses: gi0baro/setup-poetry-bin@v1
with:
virtualenvs-in-project: true

- name: Load cached .venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/requirements.yml') }}

- name: Install dependencies
run: set -eux; make install-deps
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make install-deps

- name: Run linting tasks
run: set -eux; make lint
run: make lint

integration-molecule:
name: Integration check on macOS with various molecule scenarios
runs-on: macos-${{ matrix.os }}
integration-macos-molecule:
name: Integration on macOS
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 4
matrix:
os: ["12"]
python-version: ["3.9"]
os: ["macos-12"]
scenario: ["defaults-restored-on-localhost"]

steps:
- name: Check out the codebase
uses: actions/checkout@v3
with:
submodules: true

- name: Setup python3
uses: actions/setup-python@v4
- name: Check out the actions/cache source
uses: actions/checkout@v3
with:
python-version: ${{ matrix.python-version }}
repository: actions/cache
ref: v3
path: .tmp/actions/cache

- name: Install poetry
- name: Check out fix - make actions/cache@v3 run always, not only when job succeeds
run: |
sed -i -e '/ post-if: /d' .tmp/actions/cache/action.yml
- name: Install poetry into system
uses: gi0baro/setup-poetry-bin@v1
with:
virtualenvs-in-project: true

- name: Load cached .venv
id: cached-poetry-dependencies
uses: ./.tmp/actions/cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}-${{ hashFiles('**/requirements.yml') }}

- name: Install test dependencies
run: export INSTALL_POETRY=false; make install
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: make install-deps

- name: Run molecule tests
- name: Test the playbook with molecule
run: poetry run molecule test --scenario-name "${SCENARIO}" -- -v
env:
SCENARIO: ${{ matrix.scenario}}
SCENARIO: ${{ matrix.scenario }}
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish:
if: github.event.inputs.shouldPublish == 'yes' || github.ref == 'refs/heads/master'
needs:
- lint
- integration-molecule
- integration-macos-molecule
runs-on: ubuntu-latest
steps:
- name: Publish to Ansible Galaxy
uses: robertdebock/galaxy-action@1.2.1
with:
galaxy_api_key: ${{ secrets.GALAXY_API_KEY }}

...
2 changes: 2 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
release-type: node
package-name: ansible-role-dock
default-branch: master

...
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
*/__pycache__
*.pyc
.cache
poetry.lock
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "contrib/poetry-bin"]
path = contrib/poetry-bin
url = https://github.com/gi0baro/poetry-bin
21 changes: 21 additions & 0 deletions .later.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

ansible:

# List of allowed literal bools (ANSIBLE0014)
literal-bools:
- "true"
- "false"
- "yes"
- "no"

# Global settings for all defined rules
rules:
# List of files to exclude
exclude_files:
- ./contrib
- ./.venv

version: "1.0"

...
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down Expand Up @@ -35,11 +35,13 @@ repos:
- .[community]

- repo: https://github.com/robertdebock/pre-commit
rev: v1.4.5
rev: v1.5.1
hooks:
- id: ansible_role_find_unused_variable
- id: ansible_role_find_empty_files
- id: ansible_role_find_empty_directories
- id: ansible_role_fix_readability
- id: ansible_role_find_undefined_handlers
- id: ansible_role_find_unquoted_values

...
1 change: 1 addition & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extends: default

ignore: |
contrib
.venv

# Overwrite above default rules
rules:
Expand Down
93 changes: 25 additions & 68 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
###

export ANSIBLE_FORCE_COLOR = 1
export ANSIBLE_JINJA2_NATIVE = true

export PY_COLORS = 1
export PYTHONIOENCODING = UTF-8
export LC_CTYPE = en_US.UTF-8
Expand All @@ -14,97 +12,55 @@ export LANG = en_US.UTF-8
# https://stackoverflow.com/questions/50009505/ansible-stdout-formatting
export ANSIBLE_STDOUT_CALLBACK = unixy

TASK_TAGS ?= "dock-validate dock-install dock-manipulate dock-add dock-remove dock-move"
PLAYBOOK ?= test.yml
WORKDIR ?= ./tests
INVENTORY ?= inventory.yml
TASK_TAGS ?= "dock-validate,dock-install,dock-manipulate,dock-add,dock-remove,dock-move"
REQS ?= requirements.yml
INSTALL_POETRY ?= true
POETRY ?= poetry run
POETRY_BIN ?= poetry
POETRY_RUNNER ?= poetry run
ANSIBLE_LATER_BIN = ansible-later

# leave empty to disable
# -v - verbose;
# -vvv - more details
# -vv - more details
# -vvv - enable connection debugging
DEBUG_VERBOSITY ?= -vvv

TEST_PLAYBOOK = $(POETRY) ansible-playbook $(PLAYBOOK) -i $(INVENTORY) $(DEBUG_VERBOSITY)
TEST_IDEMPOTENT = $(TEST_PLAYBOOK) | tee /dev/tty | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1)

### Lint yaml files
lint: check-syntax
$(POETRY) yamllint .
cd $(WORKDIR) && $(POETRY) ansible-lint $(PLAYBOOK) -c ../.ansible-lint
lint: later
$(POETRY_RUNNER) yamllint .
$(POETRY_RUNNER) ansible-lint . --force-color
.PHONY: lint

### Run tests
test:
cd $(WORKDIR) && $(TEST_PLAYBOOK)
.PHONY: test

test-idempotent:
cd $(WORKDIR) && $(TEST_IDEMPOTENT)
.PHONY: test-idempotent

test-validate: TASK_TAGS="dock-validate"
test-validate: test-tag

test-install: TASK_TAGS="dock-install"
test-install: test-tag

test-manipulate: TASK_TAGS="dock-manipulate"
test-manipulate: test-tag

test-add: TASK_TAGS="dock-add"
test-add: test-tag

test-remove: TASK_TAGS="dock-remove"
test-remove: test-tag

test-move: TASK_TAGS="dock-move"
test-move: test-tag

test-tag:
cd $(WORKDIR) && $(TEST_PLAYBOOK) --tags $(TASK_TAGS)
.PHONY: test-tag

#m-test:
# poetry run molecule test -- $(DEBUG_VERBOSITY)
#.PHONY: m-test

m-local:
poetry run molecule test --scenario-name defaults-restored-on-localhost -- -vvv --tags $(TASK_TAGS)
$(POETRY_RUNNER) molecule test --scenario-name defaults-restored-on-localhost -- $(DEBUG_VERBOSITY) --tags $(TASK_TAGS)
.PHONY: m-local

m-remote:
poetry run molecule test --scenario-name defaults-restored-over-ssh -- -vvv --tags $(TASK_TAGS)
$(POETRY_RUNNER) molecule test --scenario-name defaults-restored-over-ssh -- $(DEBUG_VERBOSITY) --tags $(TASK_TAGS)
.PHONY: m-remote

login-mac:
$(POETRY_RUNNER) molecule login \
--host macos-12-vm \
--scenario-name defaults-restored-over-ssh
.PHONY: login-mac

debug-version:
ansible --version
$(POETRY_RUNNER) ansible --version
.PHONY: debug-version

check:
cd $(WORKDIR) && $(TEST_PLAYBOOK) --check
.PHONY: check

### List all hostnames
ls-host:
cd $(WORKDIR) && $(POETRY) ansible all -i $(INVENTORY) -m shell -a "hostname;"
.PHONY: ls-host

### Check playbook syntax
check-syntax:
cd $(WORKDIR) && $(TEST_PLAYBOOK) --syntax-check
.PHONY: check-syntax
later:
$(POETRY_RUNNER) $(ANSIBLE_LATER_BIN) **/*.yml
.PHONY: later

### Install ansible dependencies
install: install-poetry install-deps
.PHONY: install

install-deps:
poetry install
$(POETRY) ansible-galaxy install -r $(REQS)
$(POETRY_BIN) install
$(POETRY_RUNNER) ansible-galaxy install -r $(REQS)
.PHONY: install-deps

install-poetry:
Expand All @@ -118,5 +74,6 @@ endif

### Git
hooks:
pre-commit install
.PHONY: install-hooks
$(POETRY_RUNNER) pre-commit install
$(POETRY_RUNNER) pre-commit autoupdate
.PHONY: hooks
Loading

0 comments on commit 88322cb

Please sign in to comment.