From cefbda7298d8d2dd840cb3362fcd7bbfeedc90dc Mon Sep 17 00:00:00 2001 From: madereddy <49539048+madereddy@users.noreply.github.com> Date: Tue, 12 Dec 2023 10:12:53 -0500 Subject: [PATCH] Add Redeploy --- README.md | 6 +----- playbooks/deploy.yml | 13 +------------ playbooks/fresh_install.yml | 4 ++++ playbooks/redeploy.yml | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 17 deletions(-) create mode 100644 playbooks/redeploy.yml diff --git a/README.md b/README.md index a67be37..769ba57 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,6 @@ This repo serves to work with my blog post on using Ansible to automate your hom - You must have ansible installed on your local machine. You do not need Ansible installed on the target hosts. -- Additional Ansible Roles to install -``` -ansible-galaxy install roles-ansible.restic -``` ### To Use These Playbooks Simply clone this repository and follow the blog post below to get started @@ -27,10 +23,10 @@ Simply clone this repository and follow the blog post below to get started ├── docker_status.yml ├── docker_update_containers.yml ├── deploy.yml + ├── redeploy.yml ├── clean.yml ├── fresh_install.yml ├── install_docker.yml - ├── install_vim.yml ├── os_family_discovery.yml ├── ping_test.yml └── update_upgrade.yml diff --git a/playbooks/deploy.yml b/playbooks/deploy.yml index 923dc6f..2a2adcd 100644 --- a/playbooks/deploy.yml +++ b/playbooks/deploy.yml @@ -4,17 +4,6 @@ - name: Clone repo ansible.builtin.command: cmd: git clone http://192.168.1.157:3000/jeet/OCI_Build.git - - - name: Pull backups - shell: | - unset HISTFILE - export RESTIC_REPOSITORY="s3:idnfqwbge7v2.compat.objectstorage.us-ashburn-1.oraclecloud.com/madereddy-docker-backup" - export AWS_ACCESS_KEY_ID="5195c76754bda8137f89f7141e2915f203eeeae8" - export AWS_SECRET_ACCESS_KEY="PYWvfbsdu6ZFrtTZBBhnWVXmWCp40/cRI/C3yphVOHI=" - export RESTIC_PASSWORD= ei&SNrq!7t^Zqkc2#^H6DYvR5^X32HGnUUnd#n - restic init - cd ~/OCI_Build/docker - restic restore latest:/gcloud --target ./ - name: Start container using Docker Compose ansible.builtin.command: @@ -31,4 +20,4 @@ args: chdir: ~/OCI_Build/docker register: container_status - ignore_errors: yes + ignore_errors: yes \ No newline at end of file diff --git a/playbooks/fresh_install.yml b/playbooks/fresh_install.yml index cbebd3b..fcfecda 100644 --- a/playbooks/fresh_install.yml +++ b/playbooks/fresh_install.yml @@ -47,6 +47,10 @@ - restic state: present when: ansible_os_family == "RedHat" + + - name: Update Restic Binaries + ansible.builtin.command: + cmd: restic self-update # This will run after the previous play is completed - import_playbook: install_docker.yml diff --git a/playbooks/redeploy.yml b/playbooks/redeploy.yml new file mode 100644 index 0000000..1d1d771 --- /dev/null +++ b/playbooks/redeploy.yml @@ -0,0 +1,35 @@ +- name: Rebuild OCI Stack + hosts: Docker + tasks: + - name: Create folder + ansible.builtin.file: + path: ~/OCI_Build + state: directory + mode: '0755' + + - name: Pull backups + shell: | + unset HISTFILE + export RESTIC_REPOSITORY="s3:idnfqwbge7v2.compat.objectstorage.us-ashburn-1.oraclecloud.com/madereddy-docker-backup" + export AWS_ACCESS_KEY_ID="5195c76754bda8137f89f7141e2915f203eeeae8" + export AWS_SECRET_ACCESS_KEY="PYWvfbsdu6ZFrtTZBBhnWVXmWCp40/cRI/C3yphVOHI=" + export RESTIC_PASSWORD=ei\&SNrq\!7t^Zqkc2#^H6DYvR5^X32HGnUUnd#n + cd ~/OCI_Build/docker + restic restore latest:/source/gcloud --target ./ + + - name: Start container using Docker Compose + ansible.builtin.command: + cmd: docker compose up -d + chdir: ~/OCI_Build/docker + ignore_errors: yes + + - name: Pause for 30 seconds to allow containers to stabilize + ansible.builtin.pause: + seconds: 30 + + - name: Check container status + ansible.builtin.shell: docker compose ps -q | xargs -n1 docker container inspect --format '{{ "{{" }} .State.Running {{ "}}" }}' + args: + chdir: ~/OCI_Build/docker + register: container_status + ignore_errors: yes