-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.yml
More file actions
95 lines (77 loc) · 2.34 KB
/
main.yml
File metadata and controls
95 lines (77 loc) · 2.34 KB
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
---
- hosts: localhost
connection: local
gather_facts: no
vars:
base_image: debian:bookworm
container_name: php_apache_build_container
image_namespace: geerlingguy
image_name: php-apache
# Apache settings.
apache_remove_default_vhost: yes
# PHP settings.
php_version: '8.3'
php_packages_extra:
- libapache2-mod-php8.3
php_install_recommends: no
# Handy utilities.
handy_utilities:
- curl
- unzip
- tar
- sudo
pre_tasks:
- name: Make the latest version of the base image available locally.
docker_image:
name: '{{ base_image }}'
source: pull
force_source: true
- name: Create the Docker container.
docker_container:
image: '{{ base_image }}'
name: '{{ container_name }}'
command: sleep infinity
- name: Add the newly created container to the inventory.
add_host:
hostname: '{{ container_name }}'
ansible_connection: docker
- name: Ensure Python is installed.
raw: >
apt-get update &&
apt-get install -y --no-install-recommends python3
delegate_to: '{{ container_name }}'
- name: Gather facts inside the container.
setup:
delegate_to: '{{ container_name }}'
- name: Install handy utilities.
package:
name: "{{ item }}"
state: present
with_items: "{{ handy_utilities }}"
delegate_to: '{{ container_name }}'
roles:
- name: geerlingguy.apache
delegate_to: '{{ container_name }}'
- name: geerlingguy.php-versions
delegate_to: '{{ container_name }}'
- name: geerlingguy.php
delegate_to: '{{ container_name }}'
- name: geerlingguy.php-mysql
delegate_to: '{{ container_name }}'
- name: geerlingguy.composer
delegate_to: '{{ container_name }}'
post_tasks:
- name: Clean up the container.
shell: >
apt-get remove --purge -y python &&
rm -rf /var/lib/apt/lists/*
delegate_to: '{{ container_name }}'
- name: Commit the container.
command: >
docker commit
-c 'CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]'
{{ container_name }} {{ image_namespace }}/{{ image_name }}:{{ php_version }}
- name: Remove the container.
docker_container:
name: '{{ container_name }}'
state: absent