ansible-copy

This commit is contained in:
James Turland 2024-04-26 16:23:25 +01:00
parent cac5d0df8a
commit 8623f316a6
6 changed files with 223 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,8 @@
---
docker:
hosts:
docker01:
ansible_host: 192.168.200.50
ansible_user: 'ubuntu'
ansible_become: true
ansible_become_method: sudo

View file

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

View file

@ -0,0 +1,108 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Jim's Garage Ansible Demo</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
.hero {
background: url(Jims-Garage-1.png) no-repeat center center;
background-size: cover;
height: 400px;
display: flex;
align-items: center;
justify-content: center;
color: white;
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.7);
}
.features {
margin-top: 50px;
text-align: center;
}
.feature {
padding: 20px;
transition: transform 0.3s ease;
}
.feature:hover {
transform: scale(1.05);
}
.footer {
background-color: #333;
color: white;
text-align: center;
padding: 20px;
position: fixed;
width: 100%;
bottom: 0;
}
</style>
</head>
<body>
<!-- Navigation Bar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">My Webpage</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#features">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
</ul>
</div>
</nav>
<!-- Hero Section -->
<div class="hero" id="home">
<h1>Welcome to Jim's Garage Ansible Demo</h1>
</div>
<!-- Features Section -->
<div class="container features" id="features">
<h2>Our Features</h2>
<div class="row">
<div class="col-md-4">
<div class="feature">
<i class="fas fa-cogs fa-3x"></i>
<h4>Feature 1</h4>
<p>Dynamic and interactive elements.</p>
</div>
</div>
<div class="col-md-4">
<div class="feature">
<i class="fas fa-bolt fa-3x"></i>
<h4>Feature 2</h4>
<p>Responsive design and transitions.</p>
</div>
</div>
<div class="col-md-4">
<div class="feature">
<i class="fas fa-heart fa-3x"></i>
<h4>Feature 3</h4>
<p>Engaging user experiences.</p>
</div>
</div>
</div>
</div>
<!-- Footer Section -->
<div class="footer">
<p>© 2024 My Webpage. All rights reserved.</p>
</div>
</body>
</html>