# commande pour lancer le playbook: ansible-playbook creation_nouveau_site.yml
# attention - Par défaut ce scipt se lancer vers ligatures
+# pour ne jouer que la partie permettant de générer le certificat SSL pour le HTTPS lancer la commance ci-dessous:
+# ansible-playbook creation_nouveau_site.yml --tags "https"
+
+# pour ne jouer que la partie permettant de configrer un accès SFTP lancer la commance ci-dessous:
+# ansible-playbook creation_nouveau_site.yml --tags "https"
+
- name: Promp pour définir les variables du nouveau ite
- hosts: vm_debian11 # test avec un nom de vm
+ hosts: ligatures
become: true # toutes les tâches seront pas défaut éxécuter en tant que root
vars:
# config_nginx: true à l'avenir on pourrait demander à l'utilisateur de choisir si il veut configurer nginx
- php_version: 8.0
- postgres_version: 15
- nouvelle_version: 27.1.6 # nextcloud
- ancienne_version: 27.1.5 # nextcloud
vars_prompt:
- name: SITE
- prompt: 'quel type de site?(ex: nuage, www, wiki, paheko)'
+ prompt: 'quel type de site?(ex: nuage, www, paheko ou WP)'
private: false
- default: "paheko"
+ default: "nuage"
- name: TLD
prompt: 'TLD du site à mettre à jour?(ex: org)'
private: false
default: "lhc"
- - name: config_php
- prompt: 'Faut-il configurer un pool PHP?(ex: oui/non)'
- private: false
- default: "non"
-
- name: besoin_https
prompt: 'Faut-il configurer un certificat ssl pour le HTTPS?(ex: oui/non)'
private: false
default: "non"
- - name: sftp
- prompt: 'besoin de configurer un accès SFTP pour ce compte (ex: oui/non)'
- private: false
- default: "non"
+ # pre_tasks:
- - name: sftp_key
- prompt: "Entrer la clé publique à autoriser pour l'acces SFTP (si nécessaire)"
- private: false
- default: "non"
-
- pre_tasks:
-
- - name: Vérifier le sigle n'est pas déjà utilisé
- ansible.builtin.lineinfile:
- dest: /etc/passwd
- search_string: "site_{{ SIGLE }}"
- state: absent
- check_mode: true
- changed_when: false
- register: presence_sigle
- failed_when: presence_sigle.changed
+ # - name: Vérifier le sigle n'est pas déjà utilisé
+ # ansible.builtin.lineinfile:
+ # dest: /etc/passwd
+ # search_string: "site_{{ SIGLE }}_{{ SITE }}"
+ # state: absent
+ # check_mode: true
+ # changed_when: false
+ # register: presence_sigle
+ # failed_when: presence_sigle.changed
tasks:
+ - name: Inclure les configurations optionnelles d'un site www
+ ansible.builtin.include_tasks: tasks/config_options_www.yml
+ tags:
+ - https
+ - sftp
+
- name: Inclure la configuration d'un site web basique
ansible.builtin.include_tasks: tasks/config_www.yml
+ - name: Inclure la configuration nginx
+ ansible.builtin.include_tasks: tasks/config_nginx.yml
+ vars:
+ template_site: "{{ SITE }}"
+ when: besoin_https == 'non'
+
- name: Bloc permettant de générer les certificats SSL
when: besoin_https == 'oui'
+ tags: https
block:
- name: Inclure la configuration nginx http
ansible.builtin.include_tasks: tasks/config_nginx.yml
vars:
template_site: 'http'
- - name: Générer un certififat avec certbot # noqa : command-instead-of-module
+ - name: Générer le certififat du sous-domaine avec certbot # noqa : command-instead-of-module
+ become: true
+ ansible.builtin.command: 'certbot certonly -n --nginx -d {{ config_ss_domain | default(SITE) }}.{{ DOMAIN }}.{{ TLD }}'
+ register: certbot_log
+ ignore_errors: true
+ changed_when: false
+ when: config_ss_domain != 'www'
+
+ - name: Générer le certififat du domaine et du sous-domaine avec certbot quand le sous domaine est www # noqa : command-instead-of-module
become: true
- ansible.builtin.command: 'certbot certonly -i nginx -d {{ SITE }}.{{ DOMAIN }}.{{ TLD }}'
+ ansible.builtin.command: 'certbot certonly -n --nginx -d {{ DOMAIN }}.{{ TLD }} -d {{ config_ss_domain | default(SITE) }}.{{ DOMAIN }}.{{ TLD }}'
register: certbot_log
+ ignore_errors: true
changed_when: false
+ when: config_ss_domain == 'www'
- name: Afficher les logs certbot
ansible.builtin.debug:
var: certbot_log
when: certbot_log is defined
+ - name: Activer la conf ssl dans nginx
+ ansible.builtin.set_fact:
+ ssl_ready: true
+ when: certbot_log is defined
- - name: Inclure la configuration nginx
- ansible.builtin.include_tasks: tasks/config_nginx.yml
- vars:
- template_site: "{{ SITE }}"
+ - name: Inclure la configuration nginx avec ssl
+ ansible.builtin.include_tasks: tasks/config_nginx.yml
+ vars:
+ template_site: "{{ SITE }}"
- name: Inclure la configuration d'un pool PHP
ansible.builtin.include_tasks: tasks/config_pool_php.yml
- when: config_php == 'oui' or SITE == 'paheko' or SITE == 'nuage'
+ when: config_php == 'oui' or SITE == 'paheko' or SITE == 'WP' or SITE == 'nuage'
+
+ - name: Inclure la configuration d'une bdd postgres
+ ansible.builtin.include_tasks: tasks/config_postgres.yml
+ when: config_bdd == 'postgres' or SITE == 'nuage'
+
+ - name: Inclure la configuration d'une bdd mariadb
+ ansible.builtin.include_tasks: tasks/config_mariadb.yml
+ when: config_bdd == 'mariadb' or SITE == 'WP'
- name: Inclure la configuration nextcloud si besoin
ansible.builtin.include_tasks: tasks/config_nuage.yml
ansible.builtin.include_tasks: tasks/config_paheko.yml
when: SITE == 'paheko'
- # MAJ borgmatic conf
-## Mettre à jour la conf de borgmatic pour intégrer les dossiers du nouveau nuage dans 'source_directories'
+ - name: Inclure la configuration WP si besoin
+ ansible.builtin.include_tasks: tasks/config_WP.yml
+ when: SITE == 'WP'
- # vim /etc/borgmatic/config.yaml
+ - name: Inclure le configuration du backup
+ ansible.builtin.include_tasks: tasks/config_backup.yml
- # - /home/sites/data/${TLD}/${DOMAIN}/${SITE}/config
- # - /home/sites/data/${TLD}/${DOMAIN}/${SITE}/data
\ No newline at end of file
+ - name: Inclure le configuration SFTP
+ ansible.builtin.include_tasks:
+ file: tasks/config_sftp.yml
+ apply:
+ tags: sftp
+ when: sftp_key != '' and sftp_key != 'non'
+ tags: sftp