Skip to content

Commit 6402842

Browse files
committed
fix
1 parent 0dd0281 commit 6402842

6 files changed

Lines changed: 65 additions & 71 deletions

File tree

ansible/playbooks/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
hosts: webservers
44
become: yes
55
roles:
6-
- app_deploy
6+
- web_app
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
---
22
- name: System provisioning tasks
3+
tags:
4+
- common
5+
- packages
36
block:
47
- name: Update apt cache
5-
apt:
6-
update_cache: yes
8+
ansible.builtin.apt:
9+
update_cache: true
710
cache_valid_time: 3600
8-
register: apt_update
9-
until: apt_update is success
11+
register: common_apt_update
12+
until: common_apt_update is success
1013
retries: 3
1114
delay: 5
1215

1316
- name: Install common packages
14-
apt:
17+
ansible.builtin.apt:
1518
name: "{{ common_packages }}"
1619
state: present
1720

1821
rescue:
19-
- name: "Rescue: fix apt if update failed"
20-
command: apt-get update --fix-missing
22+
- name: Rescue: fix apt if update failed
2123
when: ansible_os_family == "Debian"
24+
ansible.builtin.command: apt-get update --fix-missing
25+
changed_when: false
2226

2327
always:
24-
- name: "Always: log completion"
25-
file:
28+
- name: Always: log completion
29+
ansible.builtin.file:
2630
path: /tmp/common_role_completed
2731
state: touch
2832
mode: '0644'
2933

30-
tags:
31-
- common
32-
- packages
33-
3434
- name: User management tasks
35+
when: common_create_app_user | default(false)
36+
tags:
37+
- users
3538
block:
36-
- name: Create a dedicated user (if needed)
37-
user:
39+
- name: Create a dedicated user
40+
ansible.builtin.user:
3841
name: "{{ common_user | default('appuser') }}"
3942
state: present
4043
groups: sudo
41-
shell: /bin/bash
42-
43-
when: create_app_user | default(false) | bool
44-
tags:
45-
- users
44+
shell: /bin/bash
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
- name: restart docker
3-
service:
3+
ansible.builtin.service:
44
name: docker
55
state: restarted
Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,63 @@
11
---
22
- name: Docker installation tasks
3+
tags:
4+
- docker
5+
- docker_install
36
block:
47
- name: Add Docker GPG key
5-
apt_key:
8+
ansible.builtin.apt_key:
69
url: https://download.docker.com/linux/ubuntu/gpg
710
state: present
8-
register: gpg_result
9-
until: gpg_result is success
11+
register: docker_gpg_result
12+
until: docker_gpg_result is success
1013
retries: 5
1114
delay: 10
1215

1316
- name: Add Docker repository
14-
apt_repository:
17+
ansible.builtin.apt_repository:
1518
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
1619
state: present
1720

1821
- name: Install Docker packages
19-
apt:
22+
ansible.builtin.apt:
2023
name: "{{ docker_packages }}"
2124
state: present
22-
update_cache: yes
25+
update_cache: true
2326

2427
- name: Install Python Docker module
25-
pip:
28+
ansible.builtin.pip:
2629
name: docker
2730
state: present
2831

2932
rescue:
30-
- name: "Rescue: wait and retry GPG key"
31-
pause:
33+
- name: Rescue: wait and retry GPG key
34+
ansible.builtin.pause:
3235
seconds: 10
33-
when: gpg_result is failed
36+
when: docker_gpg_result is failed
3437

3538
always:
36-
- name: "Always: ensure Docker service is enabled and started"
37-
service:
39+
- name: Always ensure Docker service is enabled and started
40+
ansible.builtin.service:
3841
name: docker
3942
state: started
40-
enabled: yes
43+
enabled: true
4144

45+
- name: Docker configuration tasks
4246
tags:
4347
- docker
44-
- docker_install
45-
46-
- name: Docker configuration tasks
48+
- docker_config
4749
block:
4850
- name: Add user to docker group
49-
user:
51+
ansible.builtin.user:
5052
name: "{{ docker_user }}"
5153
groups: docker
52-
append: yes
54+
append: true
5355
notify: restart docker
5456

5557
- name: Configure Docker daemon (optional)
56-
template:
58+
when: docker_custom_config | default(false)
59+
ansible.builtin.template:
5760
src: daemon.json.j2
5861
dest: /etc/docker/daemon.json
59-
notify: restart docker
60-
when: docker_custom_config | default(false) | bool
61-
62-
tags:
63-
- docker
64-
- docker_config
62+
mode: '0644'
63+
notify: restart docker
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
---
2-
# Wipe logic
32
- name: Include wipe tasks
43
include_tasks: wipe.yml
5-
when: web_app_wipe | bool
4+
when: web_app_wipe | default(false)
65
tags:
76
- web_app_wipe
87

9-
# Deployment block
108
- name: Deploy application with Docker Compose
9+
tags:
10+
- app_deploy
11+
- compose
1112
block:
1213
- name: Create application directory
13-
file:
14+
ansible.builtin.file:
1415
path: "{{ compose_project_dir }}"
1516
state: directory
1617
owner: root
1718
group: root
1819
mode: '0755'
1920

2021
- name: Template docker-compose file
21-
template:
22+
ansible.builtin.template:
2223
src: docker-compose.yml.j2
2324
dest: "{{ compose_project_dir }}/docker-compose.yml"
2425
mode: '0644'
@@ -28,23 +29,19 @@
2829
project_src: "{{ compose_project_dir }}"
2930
state: present
3031
pull: always
31-
remove_orphans: yes
32+
remove_orphans: true
3233

3334
rescue:
3435
- name: Rescue - log failure
35-
debug:
36+
ansible.builtin.debug:
3637
msg: "Deployment failed for {{ app_name }}"
3738

3839
always:
3940
- name: Always - check container status
40-
command: docker ps --filter "name={{ app_name }}" --format "table {{.Names}}\t{{.Status}}"
41+
ansible.builtin.command: docker ps --filter "name={{ app_name }}" --format "table {{.Names}}\t{{.Status}}"
4142
register: container_status
4243
changed_when: false
4344

4445
- name: Show container status
45-
debug:
46-
var: container_status.stdout_lines
47-
48-
tags:
49-
- app_deploy
50-
- compose
46+
ansible.builtin.debug:
47+
var: container_status.stdout_lines
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
---
22
- name: Wipe application
3+
tags:
4+
- web_app_wipe
35
block:
46
- name: Stop and remove containers
57
community.docker.docker_compose_v2:
68
project_src: "{{ compose_project_dir }}"
79
state: absent
8-
remove_volumes: yes
9-
remove_orphans: yes
10-
ignore_errors: yes
10+
remove_volumes: true
11+
remove_orphans: true
12+
ignore_errors: true
1113

1214
- name: Remove docker-compose file
13-
file:
15+
ansible.builtin.file:
1416
path: "{{ compose_project_dir }}/docker-compose.yml"
1517
state: absent
1618

1719
- name: Remove application directory
18-
file:
20+
ansible.builtin.file:
1921
path: "{{ compose_project_dir }}"
2022
state: absent
2123

2224
- name: Log wipe completion
23-
debug:
24-
msg: "Application {{ app_name }} wiped successfully"
25-
26-
tags:
27-
- web_app_wipe
25+
ansible.builtin.debug:
26+
msg: "Application {{ app_name }} wiped successfully"

0 commit comments

Comments
 (0)