diff --git a/Playbooks/Docker-Portainer/inventory.yaml b/Playbooks/Docker-Portainer/inventory.yaml new file mode 100644 index 0000000..80c494d --- /dev/null +++ b/Playbooks/Docker-Portainer/inventory.yaml @@ -0,0 +1,8 @@ +--- +docker: + hosts: + docker01: + ansible_host: 192.168.200.222 + ansible_user: 'ubuntu' + ansible_become: true + ansible_become_method: sudo diff --git a/Playbooks/Docker-Portainer/playbook.yaml b/Playbooks/Docker-Portainer/playbook.yaml new file mode 100644 index 0000000..6609da0 --- /dev/null +++ b/Playbooks/Docker-Portainer/playbook.yaml @@ -0,0 +1,7 @@ +--- +- name: Install Docker on Ubuntu + hosts: all + become: true + roles: + - docker_install + - portainer_deploy diff --git a/Playbooks/Docker-Portainer/roles/docker_install/handlers/main.yaml b/Playbooks/Docker-Portainer/roles/docker_install/handlers/main.yaml new file mode 100644 index 0000000..303ef11 --- /dev/null +++ b/Playbooks/Docker-Portainer/roles/docker_install/handlers/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Restart Docker + ansible.builtin.systemd: + name: docker + state: restarted diff --git a/Playbooks/Docker-Portainer/roles/docker_install/tasks/main.yaml b/Playbooks/Docker-Portainer/roles/docker_install/tasks/main.yaml new file mode 100644 index 0000000..a8cc071 --- /dev/null +++ b/Playbooks/Docker-Portainer/roles/docker_install/tasks/main.yaml @@ -0,0 +1,41 @@ +--- +- name: Ensure apt is using HTTPS + ansible.builtin.apt: + name: "{{ item }}" + state: present + loop: + - apt-transport-https + - ca-certificates + - curl + - software-properties-common + +- name: Add Docker GPG key + ansible.builtin.apt_key: + url: "https://download.docker.com/linux/ubuntu/gpg" + state: present + +- name: Add Docker repository + ansible.builtin.apt_repository: + repo: "{{ docker_apt_repository }}" + state: present + +- name: Install Docker CE + ansible.builtin.apt: + name: docker-ce + state: present + update_cache: true + +- name: Configure Docker daemon options + ansible.builtin.template: + src: "templates/docker_daemon.json.j2" + dest: "/etc/docker/daemon.json" + owner: 'root' + group: 'root' + mode: '0755' # Optional file permissions + notify: Restart Docker + +- name: Ensure Docker service is enabled and running + ansible.builtin.systemd: + name: docker + enabled: true + state: started diff --git a/Playbooks/Docker-Portainer/roles/docker_install/templates/docker_daemon.json.j2 b/Playbooks/Docker-Portainer/roles/docker_install/templates/docker_daemon.json.j2 new file mode 100644 index 0000000..7858f8e --- /dev/null +++ b/Playbooks/Docker-Portainer/roles/docker_install/templates/docker_daemon.json.j2 @@ -0,0 +1,3 @@ +{ + "storage-driver": "{{ docker_daemon_options['storage-driver'] }}" +} diff --git a/Playbooks/Docker-Portainer/roles/docker_install/vars/main.yaml b/Playbooks/Docker-Portainer/roles/docker_install/vars/main.yaml new file mode 100644 index 0000000..5105d78 --- /dev/null +++ b/Playbooks/Docker-Portainer/roles/docker_install/vars/main.yaml @@ -0,0 +1,5 @@ +--- +docker_apt_release_channel: "stable" +docker_apt_repository: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable" +docker_daemon_options: + storage-driver: "overlay2" diff --git a/Playbooks/Docker-Portainer/roles/portainer_deploy/handlers/main.yaml b/Playbooks/Docker-Portainer/roles/portainer_deploy/handlers/main.yaml new file mode 100644 index 0000000..c2c1aae --- /dev/null +++ b/Playbooks/Docker-Portainer/roles/portainer_deploy/handlers/main.yaml @@ -0,0 +1,6 @@ +--- +- name: Start Portainer + community.docker.docker_compose: + project_src: /home/ubuntu/docker-compose/portainer + state: present + restarted: true diff --git a/Playbooks/Docker-Portainer/roles/portainer_deploy/tasks/main.yaml b/Playbooks/Docker-Portainer/roles/portainer_deploy/tasks/main.yaml new file mode 100644 index 0000000..483ebae --- /dev/null +++ b/Playbooks/Docker-Portainer/roles/portainer_deploy/tasks/main.yaml @@ -0,0 +1,34 @@ +--- +- name: Ensure docker-compose is installed + ansible.builtin.package: + name: docker-compose + state: present + +- name: Ensure Docker service is running + ansible.builtin.service: + name: docker + state: started + enabled: true + +- name: Setup Portainer directory + ansible.builtin.file: + path: /home/ubuntu/docker-compose/portainer + state: directory + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + +- name: Deploy Portainer using Docker Compose + ansible.builtin.template: + src: "templates/docker_compose.yaml.j2" + dest: "/home/ubuntu/docker-compose/portainer/docker-compose.yaml" + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + notify: + - Start Portainer + +- name: Run Portainer docker-compose up + community.docker.docker_compose: + project_src: /home/ubuntu/docker-compose/portainer + state: present diff --git a/Playbooks/Docker-Portainer/roles/portainer_deploy/templates/docker_compose.yaml.j2 b/Playbooks/Docker-Portainer/roles/portainer_deploy/templates/docker_compose.yaml.j2 new file mode 100644 index 0000000..00a105f --- /dev/null +++ b/Playbooks/Docker-Portainer/roles/portainer_deploy/templates/docker_compose.yaml.j2 @@ -0,0 +1,13 @@ +version: '3.3' +services: + portainer: + image: portainer/portainer-ce:{{ portainer_version }} + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - portainer_data:/data + ports: + - "9000:9000" + restart: always + +volumes: + portainer_data: diff --git a/Playbooks/Docker-Portainer/roles/portainer_deploy/vars/main.yaml b/Playbooks/Docker-Portainer/roles/portainer_deploy/vars/main.yaml new file mode 100644 index 0000000..204bbe2 --- /dev/null +++ b/Playbooks/Docker-Portainer/roles/portainer_deploy/vars/main.yaml @@ -0,0 +1,2 @@ +--- +portainer_version: "latest" diff --git a/Playbooks/File-Copy/File-Copy-Playbook.yaml b/Playbooks/File-Copy/File-Copy-Playbook.yaml new file mode 100644 index 0000000..4eaf2ea --- /dev/null +++ b/Playbooks/File-Copy/File-Copy-Playbook.yaml @@ -0,0 +1,52 @@ +--- +- name: Deploy Docker Container with Docker Compose + hosts: all + become: true + tasks: + - name: Ensure Docker is installed + ansible.builtin.package: + name: docker + state: present + + - name: Ensure Docker service is running + ansible.builtin.service: + name: docker + state: started + enabled: true + + - name: Create a directory for Docker Compose files + ansible.builtin.file: + path: /home/ubuntu/ansible-docker/docker-compose + state: directory + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + + - name: Create a directory for Nginx website files + ansible.builtin.file: + path: /home/ubuntu/docker/nginx/web + state: directory + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + + - name: Copy docker-compose to remote host + ansible.builtin.copy: + src: /home/ubuntu/nginx/docker-compose.yaml + dest: /home/ubuntu/ansible-docker/docker-compose/docker-compose.yaml + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + + - name: Copy Nginx website folder to remote host # copies a folder - note no file extension + ansible.builtin.copy: + src: /home/ubuntu/nginx/website + dest: /home/ubuntu/docker/nginx/web + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + + - name: Start Docker Compose + community.docker.docker_compose: + project_src: /home/ubuntu/ansible-docker/docker-compose + state: present diff --git a/Playbooks/File-Copy/File-Copy-Undo-Playbook.yaml b/Playbooks/File-Copy/File-Copy-Undo-Playbook.yaml new file mode 100644 index 0000000..52118a1 --- /dev/null +++ b/Playbooks/File-Copy/File-Copy-Undo-Playbook.yaml @@ -0,0 +1,24 @@ +--- +- name: Undo Docker Compose Deployment + hosts: all + become: true + tasks: + - name: Stop Docker Container + community.docker.docker_compose: + project_src: /home/ubuntu/ansible-docker/docker-compose + state: absent + + - name: Remove Docker Compose file + ansible.builtin.file: + path: /home/ubuntu/ansible-docker/docker-compose/docker-compose.yml + state: absent + + - name: Remove Docker Compose directory + ansible.builtin.file: + path: /home/ubuntu/ansible-docker + state: absent + + - name: Remove Website directory + ansible.builtin.file: + path: /home/ubuntu/docker/nginx/web + state: absent diff --git a/Playbooks/File-Copy/inventory.yaml b/Playbooks/File-Copy/inventory.yaml new file mode 100644 index 0000000..34d1a72 --- /dev/null +++ b/Playbooks/File-Copy/inventory.yaml @@ -0,0 +1,8 @@ +--- +docker: + hosts: + docker01: + ansible_host: 192.168.200.50 + ansible_user: 'ubuntu' + ansible_become: true + ansible_become_method: sudo diff --git a/Playbooks/File-Copy/nginx/docker-compose.yaml b/Playbooks/File-Copy/nginx/docker-compose.yaml new file mode 100644 index 0000000..b0812b9 --- /dev/null +++ b/Playbooks/File-Copy/nginx/docker-compose.yaml @@ -0,0 +1,31 @@ +version: "3.9" +services: + web: + image: nginx + container_name: jimsgarage + volumes: + - /home/ubuntu/docker/nginx/templates:/etc/nginx/templates + - /home/ubuntu/docker/nginx/web/website:/usr/share/nginx/html + environment: + - NGINX_HOST=nginx.jimsgarage.co.uk + - NGINX_PORT=80 + labels: + - "traefik.enable=true" + - "traefik.http.routers.nginx.entrypoints=http" + - "traefik.http.routers.nginx.rule=Host(`nginx.jimsgarage.co.uk`)" + - "traefik.http.middlewares.nginx-https-redirect.redirectscheme.scheme=https" + - "traefik.http.routers.nginx.middlewares=nginx-https-redirect" + - "traefik.http.routers.nginx-secure.entrypoints=https" + - "traefik.http.routers.nginx-secure.rule=Host(`nginx.jimsgarage.co.uk`)" + - "traefik.http.routers.nginx-secure.tls=true" + - "traefik.http.routers.nginx-secure.service=nginx" + - "traefik.http.services.nginx.loadbalancer.server.port=80" + - "traefik.docker.network=proxy" + networks: + proxy: + security_opt: + - no-new-privileges:true + +networks: + proxy: + external: true \ No newline at end of file diff --git a/Playbooks/File-Copy/nginx/website/Jims-Garage-1.png b/Playbooks/File-Copy/nginx/website/Jims-Garage-1.png new file mode 100644 index 0000000..d5491ac Binary files /dev/null and b/Playbooks/File-Copy/nginx/website/Jims-Garage-1.png differ diff --git a/Playbooks/File-Copy/nginx/website/index.html b/Playbooks/File-Copy/nginx/website/index.html new file mode 100644 index 0000000..9deb299 --- /dev/null +++ b/Playbooks/File-Copy/nginx/website/index.html @@ -0,0 +1,108 @@ + + + + + Jim's Garage Ansible Demo + + + + + + + + + + + + +
+

Welcome to Jim's Garage Ansible Demo

+
+ + +
+

Our Features

+
+
+
+ +

Feature 1

+

Dynamic and interactive elements.

+
+
+
+
+ +

Feature 2

+

Responsive design and transitions.

+
+
+
+
+ +

Feature 3

+

Engaging user experiences.

+
+
+
+
+ + + + + \ No newline at end of file diff --git a/Playbooks/Multi-OS-Update/Update-Playbook.yaml b/Playbooks/Multi-OS-Update/Update-Playbook.yaml new file mode 100644 index 0000000..62275fc --- /dev/null +++ b/Playbooks/Multi-OS-Update/Update-Playbook.yaml @@ -0,0 +1,57 @@ +--- +- name: Update Windows, Arch Linux, and Ubuntu + hosts: all + tasks: + - name: Gather facts + ansible.builtin.setup: + + - name: Update Windows + when: ansible_facts['os_family'] == 'Windows' + ansible.windows.win_updates: + category_names: + - SecurityUpdates + - UpdateRollups + - CriticalUpdates + state: installed + register: win_update_result + + - name: Check if Windows requires a reboot + when: win_update_result.changed and win_update_result.reboot_required | default(false) + ansible.windows.win_reboot: + reboot_timeout: 600 + register: win_reboot_result + + - name: Update Arch Linux + when: ansible_facts['os_family'] == 'Arch' + community.general.pacman: + update_cache: true + upgrade: true + register: arch_update_result + + - name: Check if Arch Linux requires a reboot + when: ansible_facts['os_family'] == 'Arch' and arch_update_result.changed + ansible.builtin.stat: + path: /run/reboot-required + register: arch_reboot_required + + - name: Reboot Arch Linux if required + when: arch_reboot_required.stat.exists | default(false) + ansible.builtin.reboot: + reboot_timeout: 600 + + - name: Update Ubuntu + when: ansible_facts['os_family'] == 'Debian' + ansible.builtin.apt: + upgrade: dist + update_cache: true + + - name: Check if a reboot is required on Ubuntu + when: ansible_facts['os_family'] == 'Debian' + ansible.builtin.stat: + path: /var/run/reboot-required + register: ubuntu_reboot_required + + - name: Reboot Ubuntu if required + when: ubuntu_reboot_required.stat.exists | default(false) + ansible.builtin.reboot: + reboot_timeout: 600 diff --git a/Playbooks/Multi-OS-Update/inventory.yaml b/Playbooks/Multi-OS-Update/inventory.yaml new file mode 100644 index 0000000..a7632b8 --- /dev/null +++ b/Playbooks/Multi-OS-Update/inventory.yaml @@ -0,0 +1,14 @@ +arch: + hosts: + arch01: + ansible_host: 192.168.200.214 + ansible_user: 'root' + ansible_python_interpreter: /usr/bin/python3 + +docker: + hosts: + docker01: + ansible_host: 192.168.200.50 + ansible_user: 'ubuntu' + ansible_become: true + ansible_become_method: sudo \ No newline at end of file diff --git a/Playbooks/Secrets-Variables/File-Copy-Playbook.yaml b/Playbooks/Secrets-Variables/File-Copy-Playbook.yaml new file mode 100644 index 0000000..257ed87 --- /dev/null +++ b/Playbooks/Secrets-Variables/File-Copy-Playbook.yaml @@ -0,0 +1,67 @@ +--- +- name: Deploy Docker Container with Docker Compose + hosts: all + become: true + tasks: + - name: Include variables file + ansible.builtin.include_vars: myvars.yaml + + - name: Ensure Docker is installed + ansible.builtin.package: + name: docker + state: present + + - name: Ensure Docker service is running + ansible.builtin.service: + name: docker + state: started + enabled: true + + - name: Create a directory for Docker Compose files + ansible.builtin.file: + path: /home/ubuntu/ansible-docker/docker-compose + state: directory + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + + - name: Create a directory for Nginx website files + ansible.builtin.file: + path: /home/ubuntu/docker/nginx/web + state: directory + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + + - name: Copy docker-compose to remote host + ansible.builtin.copy: + src: /home/ubuntu/nginx/docker-compose.yaml + dest: /home/ubuntu/ansible-docker/docker-compose/docker-compose.yaml + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + + - name: Copy Nginx website folder to remote host # copies a folder - note no file extension + ansible.builtin.copy: + src: /home/ubuntu/nginx/website + dest: /home/ubuntu/docker/nginx/web + mode: '0755' # Optional file permissions + owner: ubuntu # Optional ownership + group: ubuntu # Optional group ownership + + - name: Replace old name with new name (requires Ansible >= 2.4) + ansible.builtin.replace: + path: /home/ubuntu/docker/nginx/web/website/index.html + regexp: "Jim's Garage" + replace: "{{ website_name }}" + + - name: Access and print secret + ansible.builtin.replace: + path: /home/ubuntu/docker/nginx/web/website/index.html + regexp: "Our Features" + replace: "{{ api_key }}" + + - name: Start Docker Compose + community.docker.docker_compose: + project_src: /home/ubuntu/ansible-docker/docker-compose + state: present diff --git a/Playbooks/Secrets-Variables/password b/Playbooks/Secrets-Variables/password new file mode 100644 index 0000000..7aa311a --- /dev/null +++ b/Playbooks/Secrets-Variables/password @@ -0,0 +1 @@ +password \ No newline at end of file diff --git a/Playbooks/Secrets-Variables/secrets_file.enc b/Playbooks/Secrets-Variables/secrets_file.enc new file mode 100644 index 0000000..33ec709 --- /dev/null +++ b/Playbooks/Secrets-Variables/secrets_file.enc @@ -0,0 +1 @@ +api_key: SuperSecretPassword \ No newline at end of file