From ace77b57ebf749bbd746806e066fa58bbdf230e6 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 2 Aug 2020 18:56:57 -0300 Subject: provision.yaml: Use environment value of VPS_VOLUME_NAME --- provision.env.yaml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ provision.yaml | 48 ------------------------------------------------ scripts/ci/deploy.sh | 3 ++- 3 files changed, 50 insertions(+), 49 deletions(-) create mode 100644 provision.env.yaml delete mode 100644 provision.yaml diff --git a/provision.env.yaml b/provision.env.yaml new file mode 100644 index 0000000..07fd3f0 --- /dev/null +++ b/provision.env.yaml @@ -0,0 +1,48 @@ +--- +- hosts: all + any_errors_fatal: true + gather_facts: no + pre_tasks: + - name: Install Python 2 for Ansible fact gathering + raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal) + +- hosts: all + any_errors_fatal: true + tasks: + - name: Update Ubuntu server + apt: + update_cache: yes + upgrade: dist + - name: Install apt packages + apt: + name: [ 'docker-compose', 'borgbackup' ] + state: latest + - name: Create /home/vps/ base directory + file: + path: /home/vps/ + state: directory + - name: Create symlink to attached volume + file: + src: /mnt/${VPS_VOLUME_NAME} + dest: /home/vps/volumes + state: link + - name: Copy local interpolated files to remote + copy: src={{ item.src }} dest={{ item.dest }} mode={{ item.mode }} + with_items: + - { src: './generated/restore-backup.sh', dest: '/home/vps/restore-backup.sh', mode: '500' } + - { src: './secrets/borg/borg-remote.pub', dest: '/root/.ssh/id_rsa.pub', mode: '400' } + - { src: './secrets/borg/borg-remote', dest: '/root/.ssh/id_rsa', mode: '400' } + - { src: './secrets/borg/known-hosts.txt', dest: '/root/.ssh/known_hosts', mode: '400' } + - { src: './scripts/box/bash-profile.sh', dest: '/root/.bash_profile', mode: '400' } + - { src: './generated/docker-compose.yaml', dest: '/home/vps/docker-compose.yaml', mode: '400' } + - name: Restore borg backup when we have a fresh volume + shell: /home/vps/restore-backup.sh + when: lookup('env', 'DESTROY_VOLUME') == "1" + - name: Create the required Docker network + docker_network: + name: nginx-proxy + - name: Start docker-compose + docker_compose: + project_src: /home/vps/ + pull: yes + state: present diff --git a/provision.yaml b/provision.yaml deleted file mode 100644 index a202d7f..0000000 --- a/provision.yaml +++ /dev/null @@ -1,48 +0,0 @@ ---- -- hosts: all - any_errors_fatal: true - gather_facts: no - pre_tasks: - - name: Install Python 2 for Ansible fact gathering - raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal) - -- hosts: all - any_errors_fatal: true - tasks: - - name: Update Ubuntu server - apt: - update_cache: yes - upgrade: dist - - name: Install apt packages - apt: - name: [ 'docker-compose', 'borgbackup' ] - state: latest - - name: Create /home/vps/ base directory - file: - path: /home/vps/ - state: directory - - name: Create symlink to attached volume - file: - src: /mnt/vps_persistent_volume - dest: /home/vps/volumes - state: link - - name: Copy local interpolated files to remote - copy: src={{ item.src }} dest={{ item.dest }} mode={{ item.mode }} - with_items: - - { src: './generated/restore-backup.sh', dest: '/home/vps/restore-backup.sh', mode: '500' } - - { src: './secrets/borg/borg-remote.pub', dest: '/root/.ssh/id_rsa.pub', mode: '400' } - - { src: './secrets/borg/borg-remote', dest: '/root/.ssh/id_rsa', mode: '400' } - - { src: './secrets/borg/known-hosts.txt', dest: '/root/.ssh/known_hosts', mode: '400' } - - { src: './scripts/box/bash-profile.sh', dest: '/root/.bash_profile', mode: '400' } - - { src: './generated/docker-compose.yaml', dest: '/home/vps/docker-compose.yaml', mode: '400' } - - name: Restore borg backup when we have a fresh volume - shell: /home/vps/restore-backup.sh - when: lookup('env', 'DESTROY_VOLUME') == "1" - - name: Create the required Docker network - docker_network: - name: nginx-proxy - - name: Start docker-compose - docker_compose: - project_src: /home/vps/ - pull: yes - state: present diff --git a/scripts/ci/deploy.sh b/scripts/ci/deploy.sh index d3b9dac..1a7e400 100755 --- a/scripts/ci/deploy.sh +++ b/scripts/ci/deploy.sh @@ -49,6 +49,7 @@ echo "Interpolating files with envsubst..." envsubst < ./ssh.env.conf >> ~/.ssh/config envsubst < ./hosts.env > ./generated/hosts envsubst < ./docker-compose.env.yaml > ./generated/docker-compose.yaml +envsubst < ./provision.env.yaml > ./generated/provision.yaml envsubst < ./scripts/box/user-data.env.sh > ./generated/user-data.sh envsubst < ./scripts/box/create-backup.env.sh > ./generated/create-backup.sh envsubst < ./scripts/box/restore-backup.env.sh > ./generated/restore-backup.sh @@ -99,5 +100,5 @@ echo "Done." echo "Running the Ansible provision.yaml playbook..." create-known-hosts-file -ansible-playbook -v provision.yaml > ./logs/ansible-provision.txt +ansible-playbook -v ./generated/provision.yaml > ./logs/ansible-provision.txt echo "Done." -- cgit v1.2.3