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 - name: Setup ansible
hosts: nucs hosts: nucs
tasks: tasks:
- name: create ansible directory - name: Create Ansible directory
file: file:
path: /ansible # TODO: parameterize? path: /ansible
state: directory state: directory
- name: install essential packages - name: Install essential packages
apt: apt:
pkg: pkg:
- python3-pip - python3-pip
@ -15,7 +15,7 @@
- name: Install Docker - name: Install Docker
hosts: nucs hosts: nucs
tasks: tasks:
- name: install prerequisites - name: Install prerequisites
apt: apt:
pkg: pkg:
- ca-certificates - ca-certificates
@ -24,13 +24,13 @@
- lsb-release - lsb-release
state: latest state: latest
update_cache: true update_cache: true
- name: add gpg key - name: Add Docker APT key
apt_key: apt_key:
url: https://download.docker.com/linux/ubuntu/gpg url: https://download.docker.com/linux/ubuntu/gpg
- name: add docker repository - name: Add Docker repository
apt_repository: apt_repository:
repo: deb https://download.docker.com/linux/ubuntu focal stable # TODO: parameterize distro repo: deb https://download.docker.com/linux/ubuntu focal stable # TODO: parameterize distro
- name: install docker packages - name: Install Docker packages
apt: apt:
pkg: pkg:
- docker-ce - docker-ce
@ -39,7 +39,7 @@
- docker-compose-plugin - docker-compose-plugin
state: latest state: latest
update_cache: true update_cache: true
- name: install docker module for python - name: Install Docker module for Python
pip: pip:
name: name:
- docker - docker
@ -47,35 +47,16 @@
- name: Install pizzeria static website - name: Install pizzeria static website
hosts: nucs hosts: nucs
tasks: tasks:
- name: clone the repository - name: Clone pizzeria repository
git: git:
repo: https://github.com/pizzapim/pizzeria repo: https://github.com/pizzapim/pizzeria
dest: /ansible/pizzeria # TODO: parameterize? dest: /ansible/pizzeria
- name: start the docker compose - name: Start the Docker compose
community.docker.docker_compose: community.docker.docker_compose:
project_src: /ansible/pizzeria project_src: /ansible/pizzeria
pull: true pull: true
remove_orphans: true remove_orphans: true
- name: Install syncthing - name: Install Syncthing
hosts: nucs hosts: nucs
tasks: roles:
- name: install syncthing
apt:
pkg:
- syncthing - 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