Add recovery testing to deploy.yml

This commit is contained in:
madereddy
2023-12-12 09:28:09 -05:00
parent 9eb7f0ee65
commit ca6d67393e
5 changed files with 30 additions and 10 deletions
+14 -8
View File
@@ -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.
+2 -1
View File
@@ -1,3 +1,4 @@
[defaults]
inventory = ./inventory.yml
host_key_checking = False
host_key_checking = False
vault_password_file = ./.password_file
+1 -1
View File
@@ -12,7 +12,7 @@ all:
# ansible_ssh_private_key_file: ~/.ssh/<private key>
Docker:
hosts:
host1:
test-host:
ansible_host: 192.168.1.79
ansible_user: jeet
ansible_ssh_private_key_file: ~/.ssh/id_ed25519
+11
View File
@@ -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:
+2
View File
@@ -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"