deploiement sur VM

This commit is contained in:
Alexandre Chevalier
2026-02-13 23:37:08 +01:00
parent e37f99144b
commit 2291a85b79
142 changed files with 322045 additions and 208 deletions

View File

@@ -13,17 +13,31 @@
name: 'aptitude'
update_cache: true
#Apache Configuration
- name: Install LAMP Packages
apt:
name: [ 'apache2', 'python3-pip', 'mysql-server', 'php', 'php-mysql', 'libapache2-mod-php' ]
state: present
#Swap partition in case of low RAM
- name: Check if swap file exists
stat:
path: /swapfile
register: swap_file_check
- name: Make sure pymysql is present
become: true # needed if the other tasks are not played as root
pip:
name: pymysql
state: present
- name: Create 2GB swap file (if not exists)
command: fallocate -l 2G /swapfile
when: not swap_file_check.stat.exists
- name: Set permissions on swap file
file:
path: /swapfile
owner: root
group: root
mode: '0600'
when: not swap_file_check.stat.exists
- name: Format swap file
command: mkswap /swapfile
when: not swap_file_check.stat.exists
- name: Enable swap
command: swapon /swapfile
when: not swap_file_check.stat.exists
- name: Create document root
file:
@@ -32,43 +46,6 @@
owner: "{{ app_user }}"
mode: '0755'
- name: Set up Apache virtualhost
template:
src: "files/apache.conf.j2"
dest: "/etc/apache2/sites-available/{{ http_conf }}"
notify: Reload Apache
- name: Enable new site
shell: /usr/sbin/a2ensite {{ http_conf }}
notify: Reload Apache
- name: Disable default Apache site
shell: /usr/sbin/a2dissite 000-default.conf
when: disable_default
notify: Reload Apache
# MySQL Configuration
- name: Sets the root password
mysql_user:
name: root
password: "{{ mysql_root_password }}"
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Removes all anonymous user accounts
mysql_user:
name: ''
host_all: yes
state: absent
login_user: root
login_password: "{{ mysql_root_password }}"
- name: Removes the MySQL test database
mysql_db:
name: test
state: absent
login_user: root
login_password: "{{ mysql_root_password }}"
# UFW Configuration
- name: "UFW - Allow HTTP on port {{ http_port }}"
ufw:
@@ -76,22 +53,40 @@
port: "{{ http_port }}"
proto: tcp
- name: Create docker project directory
file:
path: "{{ docker_dir_path }}"
state: directory
mode: '0755'
- name : configure docker-compose
copy:
src: "files/docker-compose.yml"
dest: "/home/{{ app_user }}/docker-compose.yml"
owner: "{{ app_user }}"
mode: '0644'
- name: Create docker compose directory
file:
path: "{{ docker_dir_path }}/dockercompose"
state: directory
mode: '0755'
- name: Install Docker plugins
apt:
name:
- docker.io
- docker-compose-v2
- docker-buildx
state: present
handlers:
- name: Reload Apache
- name: Ensure Docker service is running
service:
name: apache2
state: reloaded
name: docker
state: started
enabled: yes
- name: Restart Apache
service:
name: apache2
state: restarted
- name: Sync files content to VM
ansible.posix.synchronize:
src: "./files/" # The trailing slash is important in rsync!
dest: "{{ docker_dir_path }}/"
recursive: yes
- name: Tear down and run Docker Compose
community.docker.docker_compose_v2:
project_src: "{{ docker_dir_path }}/dockercompose"
state: present
remove_orphans: yes