Playbook d'installation pour un serveur web.

This commit is contained in:
William 2021-12-15 14:47:28 +01:00
commit 2baad0a3b9
8 changed files with 106 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/hosts.ini

17
README.md Normal file
View File

@ -0,0 +1,17 @@
# Playbook webserver
This playbook installs webserver (Nginx, Mariadb, PHP)
## Installation
Copy init file and edit values
```shell
cp hosts.example.ini hosts.ini
```
Then run playbook
```shell
ansible-playbook -i hosts.ini playbook.yml
```

6
hosts.example.ini Normal file
View File

@ -0,0 +1,6 @@
[web]
127.0.0.1 ansible_ssh_user=ubuntu
[web:vars]
mysql_root_password='motdepasse'
mysql_old_root_password='motdepasse'

9
playbook.yml Normal file
View File

@ -0,0 +1,9 @@
---
- hosts: web
become: true
roles:
- mariadb
- nginx
- php

View File

@ -0,0 +1,22 @@
---
- name: install
apt:
name:
- mariadb-server
- python-mysqldb # for mysql_db and mysql_user modules
state: present
update_cache: yes
- name: ensure service is start
service:
name: mysql
state: started
enabled: yes
- name: change root password
mysql_user:
name: root
password: '{{ mysql_root_password }}'
host: 'localhost'
login_user: root
login_password: '{{ mysql_old_root_password }}'

View File

@ -0,0 +1,7 @@
---
- name: install
apt:
name:
- nginx
state: present
update_cache: yes

View File

@ -0,0 +1,17 @@
php_version: 8.0
php_packages:
- php{{ php_version }}-common
- php{{ php_version }}-zip
- php{{ php_version }}-pdo
- php{{ php_version }}-mbstring
- php{{ php_version }}-tokenizer
- php{{ php_version }}-xml
- php{{ php_version }}-opcache
- php{{ php_version }}-mysql
- php{{ php_version }}-imap
- php{{ php_version }}-curl
- php{{ php_version }}-memcached
- php{{ php_version }}-intl
- php{{ php_version }}-gd
- php{{ php_version }}-bcmath

27
roles/php/tasks/main.yml Normal file
View File

@ -0,0 +1,27 @@
---
- name: download apt key
get_url:
url: https://packages.sury.org/php/apt.gpg
dest: /tmp/php.gpg
- name: install apt key
apt_key:
file: /tmp/php.gpg
state: present
- name: apt repository
apt_repository:
repo: deb https://packages.sury.org/php/ buster main
- name: install
apt:
name: "php{{ php_version }}-fpm"
state: present
update_cache: yes
install_recommends: no
- name: install packages
apt:
name: "{{ php_packages | list }}"
state: present
install_recommends: no