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 @@ + + +
+ +Dynamic and interactive elements.
+Responsive design and transitions.
+Engaging user experiences.
+