From ca6d67393ef9c829115f5e26d346b62ac65e8e74 Mon Sep 17 00:00:00 2001 From: madereddy <49539048+madereddy@users.noreply.github.com> Date: Tue, 12 Dec 2023 09:28:09 -0500 Subject: [PATCH] Add recovery testing to deploy.yml --- README.md | 22 ++++++++++++++-------- ansible.cfg | 3 ++- inventory.yml | 2 +- playbooks/deploy.yml | 11 +++++++++++ playbooks/fresh_install.yml | 2 ++ 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4063a46..a67be37 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,11 @@ 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 @@ -21,7 +26,8 @@ Simply clone this repository and follow the blog post below to get started └── playbooks ├── docker_status.yml ├── docker_update_containers.yml - ├── first_container.yml + ├── deploy.yml + ├── clean.yml ├── fresh_install.yml ├── install_docker.yml ├── install_vim.yml @@ -45,7 +51,7 @@ In this post, we dive into Ansible to simplify and streamline your homelab opera To get started, clone the github repo that goes along with this post: -`git clone https://github.com/jonezy35/ansible-homelab.git` +`git clone http://192.168.1.157:3000/jeet/OCI_Build.git` `cd ansible-homelab` @@ -81,18 +87,18 @@ After setting up your machines, let's focus on Docker with the `docker_status.ym If you have hosts already running docker, you will want to add them to the `inventory.yml` file in a group named `Docker`. -If you don't have any hosts running docker, pick a host that you just ran the fresh install script on and add it to the `Docker` group in your `inventory.yml`. Then execute the `first_container` playbook which will stand up your first Docker container. +If you don't have any hosts running docker, pick a host that you just ran the fresh install script on and add it to the `Docker` group in your `inventory.yml`. Then execute the `deploy` playbook which will stand up your first Docker container. -`ansible-playbook playbooks/first_container.yml` - -Now add the following to your `compose_file_paths` for the docekr host in your `inventory.yml` file: - -`~/firstContainer/docker-compose.yml` +`ansible-playbook playbooks/deploy.yml` You can now run `docker_status.yml` against your docker hosts to check the status of your containers. This playbook will return all green if your containers are all good, and it will fail if any container is in status "exited" `ansible-playbook playbooks/docker_status.yml` +To clean up the build you can run `clean.yml` against the docker hosts. + +`ansible-playbook playbooks/clean.yml --ask-become` + ## Section 6: Keeping Docker Containers Up-to-Date Lastly, we have the `docker_update_containers.yml` playbook. This playbook is crucial for updating your Docker containers with the latest images. It also re-imports the docker_status.yml playbook to check the status of containers after the update. diff --git a/ansible.cfg b/ansible.cfg index 284d1e6..98574d5 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,3 +1,4 @@ [defaults] inventory = ./inventory.yml -host_key_checking = False \ No newline at end of file +host_key_checking = False +vault_password_file = ./.password_file \ No newline at end of file diff --git a/inventory.yml b/inventory.yml index b5638ec..695381b 100644 --- a/inventory.yml +++ b/inventory.yml @@ -12,7 +12,7 @@ all: # ansible_ssh_private_key_file: ~/.ssh/ Docker: hosts: - host1: + test-host: ansible_host: 192.168.1.79 ansible_user: jeet ansible_ssh_private_key_file: ~/.ssh/id_ed25519 diff --git a/playbooks/deploy.yml b/playbooks/deploy.yml index e49ce07..923dc6f 100644 --- a/playbooks/deploy.yml +++ b/playbooks/deploy.yml @@ -4,6 +4,17 @@ - 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: diff --git a/playbooks/fresh_install.yml b/playbooks/fresh_install.yml index 2457249..cbebd3b 100644 --- a/playbooks/fresh_install.yml +++ b/playbooks/fresh_install.yml @@ -22,6 +22,7 @@ - tar - net-tools - unzip + - restic state: present when: ansible_os_family == "Debian" @@ -43,6 +44,7 @@ - tar - net-tools - unzip + - restic state: present when: ansible_os_family == "RedHat"