Skip to content

Commit c8be333

Browse files
committed
Optimize Ansible syntax
1 parent 2a5bc00 commit c8be333

12 files changed

Lines changed: 238 additions & 173 deletions

File tree

.github/workflows/main.yml

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,69 @@
1-
# This is a basic workflow to help you get started with Actions
1+
---
22

3-
name: CI
3+
name: "CI"
44

5-
# Controls when the action will run. Triggers the workflow on push or pull request
6-
# events but only for the main branch
75
on:
86
workflow_dispatch:
97
push:
10-
branches: [ main ]
8+
branches:
9+
- "main"
1110
pull_request:
12-
branches: [ main ]
11+
branches:
12+
- "main"
13+
14+
env:
15+
python_version: "3.9"
1316

1417
jobs:
1518
test:
16-
name: Molecule
17-
runs-on: ubuntu-latest
19+
name: "Molecule"
20+
runs-on: "ubuntu-latest"
1821
strategy:
1922
matrix:
2023
distro:
21-
- debian10
24+
- "debian10"
2225

2326
steps:
24-
- name: Check out the codebase.
25-
uses: actions/checkout@v2
27+
- name: "Check out the codebase"
28+
# see https://github.com/marketplace/actions/checkout
29+
uses: "actions/checkout@v2"
2630

27-
- name: Set up Python 3.
28-
uses: actions/setup-python@v2
31+
- name: "Set up Python"
32+
# see https://github.com/marketplace/actions/setup-python
33+
uses: "actions/setup-python@v2"
2934
with:
30-
python-version: '3.x'
35+
python-version: "${{ env.python_version }}"
3136

32-
- name: Install wheel for python pip.
33-
run: pip3 install wheel
37+
- name: "Cache Python packages"
38+
# see https://github.com/marketplace/actions/cache
39+
uses: "actions/cache@v2"
40+
env:
41+
cache_name: "pip"
42+
with:
43+
path: "~/.cache/pip"
44+
key: "${{ runner.os }}-${{ env.cache_name }}-${{ hashFiles('**/requirements.txt') }}"
45+
restore-keys: |
46+
${{ runner.os }}-${{ env.cache_name }}-
3447
35-
- name: Install test dependencies.
36-
run: pip3 install ansible molecule molecule-docker docker yamllint ansible-lint
48+
- name: "Install Python dependencies"
49+
run: |
50+
python -m pip install wheel
51+
python -m pip install --requirement requirements.txt
3752
38-
- name: Install galaxy roles.
39-
run: ansible-galaxy install -r requirements.yml
53+
- name: "Install galaxy roles"
54+
run: "ansible-galaxy install --role-file requirements.yml"
4055

41-
- name: (Workaround) Remove all identities except of dev from vault_identity_list.
42-
uses: jacobtomlinson/gha-find-replace@master
56+
- name: "(Workaround) Remove all identities except of dev from vault_identity_list"
57+
# See https://github.com/marketplace/actions/find-and-replace
58+
uses: "jacobtomlinson/gha-find-replace@master"
4359
with:
4460
find: "vault_identity_list.*"
4561
replace: "vault_identity_list = dev@.vault-pass.dev"
4662
include: "ansible.cfg"
4763

48-
- name: Run Molecule tests.
49-
run: molecule test
64+
- name: "Run Molecule tests"
5065
env:
51-
PY_COLORS: '1'
52-
ANSIBLE_FORCE_COLOR: '1'
53-
MOLECULE_DISTRO: ${{ matrix.distro }}
66+
PY_COLORS: "1"
67+
ANSIBLE_FORCE_COLOR: "1"
68+
MOLECULE_DISTRO: "${{ matrix.distro }}"
69+
run: "molecule test"

host_vars/server01.bvrn.de.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
3+
ansible_host: "81.169.136.237"

playbook.yml

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,78 @@
11
---
2-
- hosts: all
2+
3+
- hosts: "all"
34
become: true
45

56
vars:
67
docker_install_compose: true
78
pip_install_packages:
8-
- name: [docker, docker-compose]
9-
9+
- name:
10+
- "docker"
11+
- "docker-compose"
1012

1113
roles:
12-
- kwoodson.yedit
13-
- basic
14-
- role: docker_compose_app
14+
- "kwoodson.yedit"
15+
- name: "Set up basic stuff"
16+
role: "basic"
17+
- name: "Install Jitsi"
18+
role: "docker_compose_app"
1519
docker_compose_app_directories_create:
16-
- /opt/docker-compose/jitsi-meet
17-
- /etc/jitsi/jibri
18-
- /etc/jitsi/jicofo
19-
- /etc/jitsi/jigasi
20-
- /etc/jitsi/jvb
21-
- /etc/jitsi/prosody/config
22-
- /etc/jitsi/prosody/prosody-plugins-custom
23-
- /etc/jitsi/transcripts
24-
- /etc/jitsi/web/letsencrypt
25-
docker_compose_app_appname: jitsi-meet
26-
docker_compose_app_github_repo: jitsi/docker-jitsi-meet
27-
- role: docker_compose_app
28-
docker_compose_app_repo_url: https://github.com/stefanprodan/dockprom.git
29-
docker_compose_app_appname: dockprom
20+
- "/opt/docker-compose/jitsi-meet"
21+
- "/etc/jitsi/jibri"
22+
- "/etc/jitsi/jicofo"
23+
- "/etc/jitsi/jigasi"
24+
- "/etc/jitsi/jvb"
25+
- "/etc/jitsi/prosody/config"
26+
- "/etc/jitsi/prosody/prosody-plugins-custom"
27+
- "/etc/jitsi/transcripts"
28+
- "/etc/jitsi/web/letsencrypt"
29+
docker_compose_app_appname: "jitsi-meet"
30+
docker_compose_app_github_repo: "jitsi/docker-jitsi-meet"
31+
32+
- role: "docker_compose_app"
33+
docker_compose_app_repo_url: "https://github.com/stefanprodan/dockprom.git"
34+
docker_compose_app_appname: "dockprom"
3035
docker_compose_copy_env_file: false
3136
docker_compose_deploy_default: false
3237

3338
tasks:
34-
- name: Modify dockprom docker-compose.yml file.
39+
- name: "Modify dockprom docker-compose.yml file"
3540
yedit:
36-
src: /opt/docker-compose/dockprom/docker-compose.yml
41+
src: "/opt/docker-compose/dockprom/docker-compose.yml"
3742
key: "{{ item.key }}"
3843
value: "{{ item.value }}"
3944
state: "{{ item.state }}"
40-
with_items:
41-
- key: services.grafana.environment
42-
state: absent
43-
value:
44-
- key: services.grafana.ports
45-
state: present
45+
loop:
46+
- key: "services.grafana.environment"
47+
state: "absent"
48+
value: ~
49+
- key: "services.grafana.ports"
50+
state: "present"
4651
value: |
4752
- "3000:3000"
48-
- key: services.prometheus.ports
49-
state: present
53+
- key: "services.prometheus.ports"
54+
state: "present"
5055
value: |
5156
- "9090:9090"
52-
- key: services.alertmanager.ports
53-
state: present
57+
- key: "services.alertmanager.ports"
58+
state: "present"
5459
value: |
5560
- "9093:9093"
56-
- key: services.pushgateway.ports
57-
state: present
61+
- key: "services.pushgateway.ports"
62+
state: "present"
5863
value: |
5964
- "9091:9091"
60-
- name: Deploy dockprom Docker Compose.
65+
66+
- name: "Deploy dockprom Docker Compose"
6167
docker_compose:
62-
project_src: /opt/docker-compose/dockprom
68+
project_src: "/opt/docker-compose/dockprom"
6369
files:
64-
- docker-compose.yml
70+
- "docker-compose.yml"
6571
services:
66-
- prometheus
67-
- alertmanager
68-
- nodeexporter
69-
- cadvisor
70-
- grafana
71-
- pushgateway
72-
state: present
72+
- "prometheus"
73+
- "alertmanager"
74+
- "nodeexporter"
75+
- "cadvisor"
76+
- "grafana"
77+
- "pushgateway"
78+
state: "present"

requirements.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ansible
2+
molecule
3+
molecule-docker
4+
docker
5+
yamllint
6+
ansible-lint

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ansible
2+
molecule
3+
molecule-docker
4+
docker
5+
yamllint
6+
ansible-lint

roles/basic/meta/main.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
2+
23
dependencies: []
34
galaxy_info:
4-
role_name: basic
5-
author: Jan Otto
6-
description: Basic setup.
7-
license: "license (MIT)"
5+
role_name: "basic"
6+
author: "Jan Otto"
7+
description: "Basic setup"
8+
license: "MIT"
89
min_ansible_version: 2.4
910
platforms:
10-
- name: Ubuntu
11+
- name: "Ubuntu"
1112
versions:
12-
- all
13-
- name: Debian
13+
- "all"
14+
- name: "Debian"
1415
versions:
15-
- all
16+
- "all"
1617
galaxy_tags: []

roles/basic/tasks/main.yml

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
---
2-
- block:
3-
- name: Set timezone to Europe/Berlin.
4-
timezone:
5-
name: Europe/Berlin
62

7-
- name: Ansible Date
8-
debug:
9-
msg: "Timestamp: {{ ansible_date_time.date }}T{{ ansible_date_time.time }}, tz: {{ ansible_date_time.tz }}"
3+
- name: "Set timezone to Europe/Berlin"
4+
timezone:
5+
name: "Europe/Berlin"
106

11-
- name: Update apt cache.
12-
apt:
13-
update_cache: true
14-
cache_valid_time: 3600
15-
when: ansible_os_family == 'Debian'
7+
- name: "Update apt cache"
8+
apt:
9+
update_cache: true
10+
cache_valid_time: 3600
11+
when:
12+
- ansible_os_family == 'Debian'
1613

17-
- name: Install some packages.
18-
package:
19-
name:
20-
- neovim
21-
- tmux
22-
state: present
23-
24-
become: yes
14+
- name: "Install packages"
15+
package:
16+
name:
17+
- "neovim"
18+
- "tmux"
19+
state: "present"
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---
2-
docker_compose_app_directory: /opt/docker-compose
2+
docker_compose_app_directory: "/opt/docker-compose"
33
docker_compose_app_directories_create: []
4-
docker_compose_app_appname: dockercomposeapp
4+
docker_compose_app_appname: "dockercomposeapp"
55

66
# app could be cloned via git or downloaded as release
77
# docker_compose_app_repo_url and docker_compose_app_github_repo are mutually exclusive
88

99
# git clone config
1010
docker_compose_app_repo_url: None
11+
1112
# release download config
1213
docker_compose_app_github_repo: None
14+
15+
docker_compose_app_version_ref: "HEAD"
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
---
2+
23
dependencies:
3-
- role: geerlingguy.pip
4-
- role: geerlingguy.docker
4+
- role: "geerlingguy.pip"
5+
- role: "geerlingguy.docker"
56
galaxy_info:
6-
role_name: docker_compose_app
7-
author: Jan Otto
8-
description: Docker compose app.
7+
role_name: "docker_compose_app"
8+
author: "Jan Otto"
9+
description: "Docker compose app"
910
license: "license (MIT)"
1011
min_ansible_version: 2.4
1112
platforms:
12-
- name: Ubuntu
13+
- name: "Ubuntu"
1314
versions:
14-
- all
15-
- name: Debian
15+
- "all"
16+
- name: "Debian"
1617
versions:
17-
- all
18+
- "all"
1819
galaxy_tags: []
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
- name: "Clone Git repository"
4+
ansible.builtin.git:
5+
repo: "{{ docker_compose_app_repo_url }}"
6+
dest: "{{ docker_compose_app_directory }}/{{ docker_compose_app_appname }}"
7+
version: "{{ docker_compose_app_version_ref }}"
8+
force: true

0 commit comments

Comments
 (0)