From 8e8564216e755650a201b59d6d1d6ea866db236b Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Wed, 30 Nov 2022 22:34:14 +0100 Subject: [PATCH] clean up ansible script --- Makefile | 4 ++ ansible.cfg | 3 ++ .../{acceptation => }/group_vars/nucs.yml | 0 inventory/{acceptation => }/hosts.yml | 0 playbooks/nucs.yml | 47 ++++++------------- roles/syncthing/tasks/main.yml | 19 ++++++++ .../syncthing/templates}/config.xml.j2 | 0 7 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 Makefile create mode 100644 ansible.cfg rename inventory/{acceptation => }/group_vars/nucs.yml (100%) rename inventory/{acceptation => }/hosts.yml (100%) create mode 100644 roles/syncthing/tasks/main.yml rename {playbooks/files => roles/syncthing/templates}/config.xml.j2 (100%) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6c3483b --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +run: + ansible-playbook playbooks/nucs.yml -i inventory/hosts.yml + +.PHONY: run diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..2b8bf76 --- /dev/null +++ b/ansible.cfg @@ -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 diff --git a/inventory/acceptation/group_vars/nucs.yml b/inventory/group_vars/nucs.yml similarity index 100% rename from inventory/acceptation/group_vars/nucs.yml rename to inventory/group_vars/nucs.yml diff --git a/inventory/acceptation/hosts.yml b/inventory/hosts.yml similarity index 100% rename from inventory/acceptation/hosts.yml rename to inventory/hosts.yml diff --git a/playbooks/nucs.yml b/playbooks/nucs.yml index 271ec1f..9eab727 100644 --- a/playbooks/nucs.yml +++ b/playbooks/nucs.yml @@ -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: - - 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 + roles: + - syncthing diff --git a/roles/syncthing/tasks/main.yml b/roles/syncthing/tasks/main.yml new file mode 100644 index 0000000..7b3ebaf --- /dev/null +++ b/roles/syncthing/tasks/main.yml @@ -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 diff --git a/playbooks/files/config.xml.j2 b/roles/syncthing/templates/config.xml.j2 similarity index 100% rename from playbooks/files/config.xml.j2 rename to roles/syncthing/templates/config.xml.j2