clean up ansible script

This commit is contained in:
Pim Kunis 2022-11-30 22:34:14 +01:00
parent 9edab09330
commit 8e8564216e
7 changed files with 40 additions and 33 deletions

4
Makefile Normal file
View file

@ -0,0 +1,4 @@
run:
ansible-playbook playbooks/nucs.yml -i inventory/hosts.yml
.PHONY: run

3
ansible.cfg Normal file
View file

@ -0,0 +1,3 @@
[defaults]
# (pathspec) Colon separated paths in which Ansible will search for Roles.
roles_path=~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:roles

View file

@ -2,11 +2,11 @@
- name: Setup ansible
hosts: nucs
tasks:
- name: create ansible directory
- name: Create Ansible directory
file:
path: /ansible # TODO: parameterize?
path: /ansible
state: directory
- name: install essential packages
- name: Install essential packages
apt:
pkg:
- python3-pip
@ -15,7 +15,7 @@
- name: Install Docker
hosts: nucs
tasks:
- name: install prerequisites
- name: Install prerequisites
apt:
pkg:
- ca-certificates
@ -24,13 +24,13 @@
- lsb-release
state: latest
update_cache: true
- name: add gpg key
- name: Add Docker APT key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
- name: add docker repository
- name: Add Docker repository
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu focal stable # TODO: parameterize distro
- name: install docker packages
- name: Install Docker packages
apt:
pkg:
- docker-ce
@ -39,7 +39,7 @@
- docker-compose-plugin
state: latest
update_cache: true
- name: install docker module for python
- name: Install Docker module for Python
pip:
name:
- docker
@ -47,35 +47,16 @@
- name: Install pizzeria static website
hosts: nucs
tasks:
- name: clone the repository
- name: Clone pizzeria repository
git:
repo: https://github.com/pizzapim/pizzeria
dest: /ansible/pizzeria # TODO: parameterize?
- name: start the docker compose
dest: /ansible/pizzeria
- name: Start the Docker compose
community.docker.docker_compose:
project_src: /ansible/pizzeria
pull: true
remove_orphans: true
- name: Install syncthing
- name: Install Syncthing
hosts: nucs
tasks:
- name: install syncthing
apt:
pkg:
roles:
- syncthing
state: latest
update_cache: true
- name: create syncthing user
user:
name: syncthing
home: /home/syncthing
state: present
- name: copy syncthing configuration
template:
src: "{{ playbook_dir }}/files/config.xml.j2"
dest: /home/syncthing/.config/syncthing/config.xml
- name: enable syncthing service
systemd:
name: "syncthing@syncthing"
enabled: true
state: restarted

View file

@ -0,0 +1,19 @@
- name: Install Syncthing
apt:
name: syncthing
state: latest
update_cache: true
- name: Create syncthing user
user:
name: syncthing
home: /home/syncthing
state: present
- name: Copy Syncthing configuration
template:
src: "{{ role_path }}/templates/config.xml.j2"
dest: /home/syncthing/.config/syncthing/config.xml
- name: Enable Syncthing service
systemd:
name: syncthing@syncthing
enabled: true
state: restarted