split playbook into roles

This commit is contained in:
Pim Kunis 2022-12-03 13:05:55 +01:00
parent 53bba1751e
commit 62f014d90f
9 changed files with 69 additions and 64 deletions

View file

@ -1,4 +1,4 @@
run: %:
ansible-playbook playbooks/nucs.yml -i inventory/hosts.yml --ask-vault-pass ansible-playbook playbooks/$@.yml -i inventory/hosts.yml --ask-vault-pass
.PHONY: run .PHONY: run

9
playbooks/all.yml Normal file
View file

@ -0,0 +1,9 @@
---
- name: Install pizzeria static website
hosts: nucs
roles:
- pizzeria
- name: Install Syncthing
hosts: nucs
roles:
- syncthing

View file

@ -1,62 +0,0 @@
---
- name: Setup ansible
hosts: nucs
tasks:
- name: Create Ansible directory
file:
path: /ansible
state: directory
- name: Install essential packages
apt:
pkg:
- python3-pip
state: latest
update_cache: true
- name: Install Docker
hosts: nucs
tasks:
- name: Install prerequisites
apt:
pkg:
- ca-certificates
- curl
- gnupg
- lsb-release
state: latest
update_cache: true
- name: Add Docker APT key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
- name: Add Docker repository
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu focal stable # TODO: parameterize distro
- name: Install Docker packages
apt:
pkg:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
state: latest
update_cache: true
- name: Install Docker module for Python
pip:
name:
- docker
- docker-compose
- name: Install pizzeria static website
hosts: nucs
tasks:
- name: Clone pizzeria repository
git:
repo: https://github.com/pizzapim/pizzeria
dest: /ansible/pizzeria
- name: Start the Docker compose
community.docker.docker_compose:
project_src: /ansible/pizzeria
pull: true
remove_orphans: true
- name: Install Syncthing
hosts: nucs
roles:
- syncthing

4
playbooks/pizzeria.yml Normal file
View file

@ -0,0 +1,4 @@
- name: Install pizzeria static website
hosts: nucs
roles:
- pizzeria

4
playbooks/syncthing.yml Normal file
View file

@ -0,0 +1,4 @@
- name: Install syncthing
hosts: nucs
roles:
- syncthing

View file

@ -0,0 +1,8 @@
- name: Create /data directory
file:
path: /data
state: directory
- name: Create /apps directory
file:
path: /apps
state: directory

View file

@ -0,0 +1,30 @@
- name: Install Docker prerequisites
apt:
pkg:
- ca-certificates
- curl
- gnupg
- lsb-release
- python3-pip
state: latest
update_cache: true
- name: Add Docker APT key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
- name: Add Docker repository
apt_repository:
repo: "deb https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
- name: Install Docker packages
apt:
pkg:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
state: latest
update_cache: true
- name: Install Docker modules for Python
pip:
name:
- docker
- docker-compose

View file

@ -0,0 +1,3 @@
dependencies:
- role: common
- role: docker

View file

@ -0,0 +1,9 @@
- name: Clone pizzeria repository
git:
repo: https://github.com/pizzapim/pizzeria
dest: /apps/pizzeria
- name: Start the Docker compose
community.docker.docker_compose:
project_src: /apps/pizzeria
pull: true
remove_orphans: true