-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebian-docker-wordpress-install.yml
123 lines (107 loc) · 3.27 KB
/
debian-docker-wordpress-install.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
- name: install Docker
hosts: all
become: true
tasks:
- name: Install apt-transport-https
ansible.builtin.apt:
name:
- apt-transport-https
- ca-certificates
- lsb-release
- gnupg
- curl
state: latest
update_cache: true
- name: Add signing key
ansible.builtin.apt_key:
url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg"
state: present
- name: Add repository into sources list
ansible.builtin.apt_repository:
repo: "deb [arch={{ 'amd64' if ansible_architecture == 'x86_64' else ansible_architecture }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable"
state: present
filename: docker
- name: Update all packages to the latest version
apt:
upgrade: dist
- name: Install Docker
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: latest
update_cache: true
- name: Ensure group "docker" exists
ansible.builtin.group:
name: docker
state: present
- name: adding ubuntu to docker group
user:
name: "{{ user_name }}"
groups: docker
append: yes
- name: "Create .ssh dir"
ansible.builtin.file:
path: ".ssh"
state: directory
owner: "{{ user_name }}"
- name: generate SSH key id_rsa
become: no
openssh_keypair:
path: "~/.ssh/id_rsa"
type: rsa
size: 4096
state: present
force: no
- name: "Read a ssh file content"
shell: |
cat ~/.ssh/id_rsa.pub
register: file_content
become: no
- name: "Print ssh key"
debug:
msg: "{{ file_content.stdout }}"
- name: Create a directory for wordpress container
ansible.builtin.file:
path: "/home/{{ user_name }}/wordpress-container"
state: directory
mode: '0755'
- name: "Create docker-compose file with contents"
copy:
dest: "/home/{{ user_name }}/wordpress-container/docker-compose.yml"
content: |
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- wordpress:/var/www/html
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db:/var/lib/mysql
volumes:
wordpress:
db:
- name: "Start Docker container"
shell: |
cd "/home/{{ user_name }}/wordpress-container"
docker compose up -d
become: yes