Skip to content

Commit 82f2c3e

Browse files
authored
Merge pull request #8 from mdsketch/molecule
Molecule
2 parents d333429 + d7c8d17 commit 82f2c3e

File tree

15 files changed

+378
-8
lines changed

15 files changed

+378
-8
lines changed

.codespellignore

Whitespace-only changes.

.github/workflows/galaxy.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Ansible Galaxy release
3+
4+
on:
5+
release:
6+
types: [created, edited, published, released]
7+
push:
8+
tags:
9+
- "*"
10+
11+
permissions: {}
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: checkout
18+
uses: actions/checkout@v3
19+
with:
20+
path: mdsketch.teleport
21+
- name: galaxy
22+
uses: robertdebock/galaxy-action@1.2.1
23+
with:
24+
galaxy_api_key: ${{ secrets.galaxy_api_key }}
25+
path: mdsketch.teleport
26+
git_branch: main

.github/workflows/lint.yml

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
1-
name: Ansible Lint
1+
---
2+
name: lint
23
on: [push, pull_request, workflow_dispatch]
3-
44
jobs:
5-
lint:
5+
build:
66
runs-on: ubuntu-latest
7+
strategy:
8+
fail-fast: false
9+
max-parallel: 4
10+
env:
11+
ANSIBLE_CALLBACKS_ENABLED: profile_tasks
12+
ANSIBLE_EXTRA_VARS: ""
13+
ANSIBLE_ROLE: mdsketch.teleport
714

815
steps:
9-
- uses: actions/checkout@v2
10-
- name: Run ansible-lint
11-
uses: ansible-community/ansible-lint-action@v6.11.0
16+
- uses: actions/checkout@v3
17+
with:
18+
path: ${{ env.ANSIBLE_ROLE }}
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: "3.x"
23+
- name: Install dependencies
24+
run: |
25+
python3 -m pip install --upgrade pip
26+
pip3 install ansible-lint flake8 yamllint
27+
which ansible
28+
pip3 install ansible
29+
pip3 show ansible
30+
ansible --version
31+
cd $GITHUB_WORKSPACE/$ANSIBLE_ROLE
32+
[ -f molecule/default/requirements.yml ] && ansible-galaxy install -r molecule/default/requirements.yml
33+
{ echo '[defaults]'; echo 'callbacks_enabled = profile_tasks, timer'; echo 'roles_path = ../'; echo 'ansible_python_interpreter: /usr/bin/python3'; } >> ansible.cfg
34+
- name: Environment
35+
run: |
36+
pwd
37+
env
38+
find . -ls
39+
- uses: codespell-project/actions-codespell@master
40+
with:
41+
ignore_words_file: ${{ env.ANSIBLE_ROLE }}/.codespellignore
42+
skip: .git
43+
path: ${{ env.ANSIBLE_ROLE }}
44+
if: ${{ always() }}
45+
- name: yamllint
46+
run: |
47+
cd $GITHUB_WORKSPACE/$ANSIBLE_ROLE && yamllint .
48+
if: ${{ always() }}
49+
- name: ansible-lint
50+
run: |
51+
cd $GITHUB_WORKSPACE/$ANSIBLE_ROLE && ansible-lint
52+
if: ${{ always() }}

.github/workflows/molecule.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
name: molecule_tests
3+
4+
on:
5+
push:
6+
pull_request:
7+
workflow_dispatch:
8+
schedule: # run weekly, every monday 01:00
9+
- cron: "0 1 * * 1"
10+
11+
permissions: {}
12+
13+
jobs:
14+
build:
15+
permissions:
16+
contents: read
17+
runs-on: ubuntu-latest
18+
continue-on-error: ${{ matrix.experimental }}
19+
strategy:
20+
fail-fast: false
21+
max-parallel: 4
22+
matrix:
23+
include:
24+
- molecule_distro: "rockylinux:9"
25+
experimental: false
26+
- molecule_distro: "rockylinux:8"
27+
experimental: false
28+
- molecule_distro: "ubuntu:22.04"
29+
experimental: false
30+
- molecule_distro: "ubuntu:20.04"
31+
experimental: false
32+
- molecule_distro: "debian:11"
33+
experimental: false
34+
env:
35+
ANSIBLE_CALLBACKS_ENABLED: profile_tasks
36+
MOLECULE_NO_LOG: "false"
37+
ANSIBLE_ROLE: mdsketch.teleport
38+
39+
steps:
40+
- uses: actions/checkout@v3
41+
with:
42+
path: ${{ env.ANSIBLE_ROLE }}
43+
- name: Set up Python
44+
uses: actions/setup-python@v4
45+
with:
46+
python-version: "3.x"
47+
- name: Install dependencies
48+
run: |
49+
python -m pip install --upgrade pip
50+
pip install molecule[docker] ansible-lint flake8 testinfra ansible
51+
mkdir -p $HOME/.ansible/roles && ln -s $GITHUB_WORKSPACE/$ANSIBLE_ROLE $HOME/.ansible/roles/
52+
- name: Environment
53+
run: |
54+
pwd
55+
env
56+
find -ls
57+
- name: Galaxy dependencies
58+
run: |
59+
cd $GITHUB_WORKSPACE/$ANSIBLE_ROLE && ansible-galaxy install --timeout 120 --verbose -r molecule/default/requirements.yml
60+
continue-on-error: true
61+
- name: run test
62+
run: |
63+
cd $GITHUB_WORKSPACE/$ANSIBLE_ROLE && molecule test
64+
env:
65+
PY_COLORS: "1"
66+
ANSIBLE_FORCE_COLOR: "1"
67+
MOLECULE_DISTRO: ${{ matrix.molecule_distro }}

.pre-commit-config.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.4.0
5+
hooks:
6+
- id: check-yaml
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
9+
- id: check-added-large-files
10+
- id: check-json
11+
- id: detect-private-key
12+
- id: check-case-conflict
13+
- id: requirements-txt-fixer
14+
- id: check-ast
15+
- id: check-shebang-scripts-are-executable
16+
- id: check-merge-conflict
17+
- id: check-symlinks
18+
- id: check-toml
19+
- id: check-xml
20+
- id: check-docstring-first
21+
- repo: https://github.com/codespell-project/codespell
22+
rev: v2.2.4
23+
hooks:
24+
- id: codespell
25+
args: [-I, .codespellignore]
26+
- repo: https://github.com/ansible-community/ansible-lint.git
27+
rev: v6.14.2
28+
hooks:
29+
- id: ansible-lint
30+
files: \.(yaml|yml)$
31+
- repo: https://github.com/ansible-community/ansible-lint.git
32+
rev: v6.3.0
33+
hooks:
34+
- id: ansible-lint

.yamllint.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ rules:
1313
require-starting-space: true
1414
ignore-shebangs: true
1515
min-spaces-from-content: 1
16+
17+
ignore:
18+
- .git
19+
- .github
20+
- .gitignore

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pre-commit:
2+
echo "make sure you have precommit installed"
3+
echo "pip install pre-commit"
4+
echo "yay pre-commit"
5+
pre-commit install
6+
pre-commit run --all-files
7+
8+
lint:
9+
ansible-lint -p deploy.yml

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
[![Ansible Galaxy](https://img.shields.io/badge/Ansible%20Galaxy-mdsketch.teleport-blueviolet)](https://galaxy.ansible.com/mdsketch/teleport)
44
[![Ansible Lint](https://github.com/mdsketch/ansible-teleport/actions/workflows/lint.yml/badge.svg)](https://github.com/mdsketch/ansible-teleport/actions/workflows/lint.yml)
5+
[![molecule_tests](https://github.com/mdsketch/ansible-teleport/actions/workflows/molecule.yml/badge.svg)](https://github.com/mdsketch/ansible-teleport/actions/workflows/molecule.yml)
56

67
An ansible role to install or update the teleport node service and teleport config on Debian based systems.
78

89
Works with any architecture that teleport has a binary for, see available [teleport downloads](https://goteleport.com/teleport/download/).
910

1011
If you add your own teleport config file template you can run any node services you want (ssh, app, database, kubernetes)
1112

13+
## TODO:
14+
- add idempotence tests to verify teleport is updated correctly (config, service and binary)
15+
- add tests for variable templating
16+
- lock down the versions of the linting tools
17+
- investigate if installing teleport in a docker container is useful (currently not supported)
18+
1219
## Requirements
1320

1421
A running teleport cluster so that you can provide the following information:

defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ teleport_control_systemd: yes
1616
teleport_template_config: yes
1717
# Default dont change
1818
update_teleport: no
19+
20+
is_container: false

handlers/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
state: "reloaded"
77
daemon_reload: yes
88
enabled: yes
9-
when: teleport_control_systemd
9+
when:
10+
- teleport_control_systemd
11+
- not is_container | bool

molecule/default/converge.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
environment:
5+
http_proxy: "{{ lookup('env', 'http_proxy') }}"
6+
https_proxy: "{{ lookup('env', 'https_proxy') }}"
7+
no_proxy: "{{ lookup('env', 'no_proxy') }}"
8+
remote_user: root
9+
pre_tasks:
10+
- name: Ubuntu | Install python3
11+
ansible.builtin.raw: test -e /usr/bin/python3 || (apt -y update && apt install -y python3-minimal)
12+
register: python3
13+
changed_when: "'installed' in python3.stdout"
14+
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int >= 16)
15+
- name: RedHat | Install python3
16+
ansible.builtin.raw: test -e /usr/bin/python3 || (yum install -y python3)
17+
register: python3
18+
changed_when: "'installed' in python3.stdout"
19+
when: (ansible_os_family == "RedHat" and ansible_distribution_major_version | int >= 8)
20+
- name: Gather Facts
21+
ansible.builtin.setup:
22+
when: (ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int >= 16)
23+
- name: Ubuntu Bionic+, Redhat 8+ | Enforce python3 for ansible
24+
ansible.builtin.set_fact:
25+
ansible_python_interpreter: /usr/bin/python3
26+
when: >
27+
(ansible_distribution == "Ubuntu" and ansible_distribution_major_version | int >= 16) or
28+
(ansible_os_family == "RedHat" and ansible_distribution_major_version | int >= 8)
29+
- name: Debian | Refresh apt cache
30+
ansible.builtin.apt:
31+
update_cache: yes
32+
cache_valid_time: 3600
33+
when: ansible_os_family == "Debian"
34+
roles:
35+
- mdsketch.teleport

molecule/default/molecule.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
enabled: False
5+
driver:
6+
name: docker
7+
platforms:
8+
- name: instance
9+
image: ${MOLECULE_DISTRO:-ubuntu:22.04}
10+
# env:
11+
# http_proxy: ${http_proxy}
12+
# https_proxy: ${https_proxy}
13+
# no_proxy: ${no_proxy}
14+
groups:
15+
- teleportclients
16+
provisioner:
17+
name: ansible
18+
config_options:
19+
defaults:
20+
verbosity: 2
21+
scenario:
22+
name: default
23+
verifier:
24+
name: ansible

molecule/default/requirements.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
collections:
4+
- ansible.posix

0 commit comments

Comments
 (0)