modif creation dossier common app nextcloud
[lhc/ansible.git] / tasks / config_nuage.yml
index 112d408..ffb8ab7 100644 (file)
@@ -1,3 +1,7 @@
+- name: Etckeeper commit if necessary
+  ansible.builtin.command: etckeeper commit "commit by ansible because installing {{ DOMAIN }}/{{ config_ss_domain }}"
+  ignore_errors: true
+
 - name: Install required packages
   ansible.builtin.apt:
     name:
       - php-gmp
 #      - php-exif
       - php-redis
+      - imagemagick
       - php-imagick
+      - python3-psycopg2 # module ansible psql
     state: present
 
 - name: Boucle d'ajout du user php dans plusieurs groupe
   ansible.builtin.user:
-    name: "php_{{ SIGLE }}_{{ SITE }}"
+    name: "php_{{ SIGLE }}_{{ config_ss_domain }}"
     groups: "{{ item }}"
     append: true
   loop:
     - nextcloud
     - postgres-data
     - redis
-    - "site_{{ SIGLE }}_{{ SITE }}"
+    - "site_{{ SIGLE }}_{{ config_ss_domain }}"
 
-- name: Bloc nextcloud_version
+- name: Bloc nouvelle version nextcloud
   when: nouvelle_version is undefined
   block:
     - name: Demande la version de nextcloud à installer
 
     - name: Definir nouvelle_version
       ansible.builtin.set_fact:
-        nouvelle_version: "{{ nextcloud_version.user_input }}"
+        nouvelle_version: "{{ nextcloud_version_prompt.user_input }}"
 
-    - name: Demande la version de nextcloud déjà installer
+- name: Bloc ancienne version nextcloud
+  when: ancienne_version is undefined
+  block:
+    - name: Demande la version de nextcloud déjà installée
       ansible.builtin.pause:
         prompt: "Quelle version de nextcloud déjà installée"
         echo: true
 
     - name: Definir ancienne_version
       ansible.builtin.set_fact:
-        ancienne_version: "{{ ancienne_version.user_input }}"
+        ancienne_version: "{{ ancienne_version_prompt.user_input }}"
 
 - name: Inclure la verif de l'install nextcloud
   ansible.builtin.include_tasks: tasks/verif_installation_nextcloud.yml
 
-- name: "[PostgreSQL] - {{ nextcloud_php_user }} role is created."
+- name: PostgreSQL - nextcloud_php_user role is created
   become_user: postgres
   become: true
   community.postgresql.postgresql_user:
@@ -74,7 +83,7 @@
     state: present
     role_attr_flags: CREATEDB
 
-- name: "[PostgreSQL] - {{ nextcloud_db_name }} database is created."
+- name: PostgreSQL -  nextcloud_db_name  database is created
   become_user: postgres
   become: true
   community.postgresql.postgresql_db:
   community.postgresql.postgresql_privs:
     db: "{{ item.db }}"
     privs: "{{ item.privs }}"
-    type: "{{ item.type |default(omit)}}"
+    type: "{{ item.type |default(omit) }}"
     objs: "{{ item.objs }}"
     role: "{{ item.role }}"
     grant_option: "{{ item.grant_option |default(omit) }}"
   community.postgresql.postgresql_pg_hba:
     dest: "/etc/postgresql/{{ postgres_version }}/main/pg_hba.conf"
     contype: local
-    users: "php_{{ SIGLE}}_{{SITE}}"
-    databases: "php_{{ SIGLE}}_{{SITE}}"
+    users: "php_{{ SIGLE }}_{{ config_ss_domain }}"
+    databases: "php_{{ SIGLE }}_{{ config_ss_domain }}"
     method: peer
     keep_comments_at_rules: true
-    comment: "autoriser le user php_{{ SIGLE}}_{{SITE}} à se connecter à la bdd du meme nom"
+    comment: "autoriser le user php_{{ SIGLE }}_{{ config_ss_domain }} à se connecter à la bdd du meme nom"
 
 - name: Boucle création des répertoires app, config et data nextcloud
   ansible.builtin.file:
   loop_control:
     label: "{{ item.path }}"
   loop:
-    - path: "{{ nextcloud_source }}/apps"
+    - path: "{{ nextcloud_webroot }}/apps"
       state: directory
       owner: "{{ nextcloud_php_user }}"
       group: "{{ nextcloud_websrv_user }}"
       mode: '2750'
-    - path: "{{ nextcloud_source }}/config"
+    - path: "{{ nextcloud_webroot }}/config"
       state: directory
       owner: "{{ nextcloud_php_user }}"
       group: "{{ nextcloud_websrv_user }}"
       mode: '2750'
-    - path: "{{ nextcloud_source }}/data"
+    - path: "{{ nextcloud_webroot }}/data"
       state: directory
       owner: "{{ nextcloud_php_user }}"
       group: "{{ nextcloud_websrv_user }}"
 
 - name: Create nextcloud root dir symbolic link
   ansible.builtin.file:
-    src: "{{ nextcloud_source }}"
+    src: "{{ nextcloud_symbolic_source }}"
     dest: "{{ nextcloud_webroot }}/nextcloud"
     owner: nextcloud
     group: nextcloud
 
 - name: Create nextcloud common app dir symbolic link
   ansible.builtin.file:
-    src: "{{ nextcloud_common }}"
+    src: "{{ nextcloud_symbolic_common }}"
     dest: "{{ nextcloud_webroot }}/common"
     owner: nextcloud
     group: nextcloud
     state: link
     follow: false
 
-- name: créer les fichiers spécifiques nextcloud
+- name: Créer les fichiers spécifiques nextcloud
   ansible.builtin.template:
     src: "templates/{{ item.src }}"
     dest: "{{ nextcloud_webroot }}/{{ item.dest }}"
     owner: "{{ item.owner }}"
-    group: "{{ item.group}}"
+    group: "{{ item.group }}"
     mode: "{{ item.mode }}"
   loop:
     - src: "nextcloud_cron.j2"
       group: "{{ nextcloud_websrv_user }}"
       mode: '640'
 
-# - name: Lancement du script d'installation nextcloud # noqa : command-instead-of-module
-#   become_user: "{{ nextcloud_php_user }}"
-#   become: true
-#   ansible.builtin.command: >
-#           ./console maintenance:install
-#           --database='pgsql'
-#           --database-name="php_{{ SIGLE }}_{{ SITE }}"
-#           --database-user="php_{{ SIGLE }}_{{ SITE }}/data/"
-#           --database-host="/var/run/postgresql/"
-#           --admin-user='admin'
-#           --admin-pass='ckoideja'
-#           --data-dir="/home/sites/data/$TLD/{{ DOMAIN }}/{{ SITE }}/data/"
-#   args:
-#     chdir: "{{ nextcloud_webroot }}"
-#   register: install_result
+- name: Recharger plusieurs services
+  ansible.builtin.service:
+    name: "{{ item }}"
+    state: reloaded
+  loop:
+    - "postgresql"
+    - "php{{ php_version }}-fpm"
+
+- name: Lancement du script d'installation nextcloud # noqa : command-instead-of-module
+  become_user: "{{ nextcloud_php_user }}"
+  become: true
+  ansible.builtin.command: >
+          ./console maintenance:install
+          --database='pgsql'
+          --database-name="php_{{ SIGLE }}_{{ config_ss_domain }}"
+          --database-user="php_{{ SIGLE }}_{{ config_ss_domain }}"
+          --database-host="/var/run/postgresql/"
+          --database-pass=""
+          --admin-user='admin'
+          --admin-pass='ckoideja'
+          --data-dir="/home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ config_ss_domain }}/data/"
+  args:
+    chdir: "{{ nextcloud_webroot }}"
+  register: install_result
+  ignore_errors: true
 
-# - name: créer les fichiers spécifiques nextcloud
-#   ansible.builtin.template:
-#     src: "templates/{{ item.src }}"
-#     dest: "{{ nextcloud_webroot }}/{{ item.dest }}"
-#     owner: "{{ item.owner }}"
-#     group: "{{ item.group}}"
-#     mode: "{{ item.mode }}"
-#   loop:
-#     - src: "nextcloud_sigle_config.j2"
-#       dest: "config/{{ SIGLE }}.config.php"
-#       owner: "{{ nextcloud_php_user }}"
-#       group: "{{ nextcloud_websrv_user }}"
-#       mode: '640'
+- name: Afficher les logs du script d'install
+  ansible.builtin.debug:
+    var: install_result
+  when: install_result is defined
 
-# - name: Creation d'un lien symbolique vers le configuration nextcloud commun
-#   ansible.builtin.file:
-#     src: "../../../../nextcloud/common/common.config.php"
-#     dest: "config/common.config.php"
-#     owner: nextcloud
-#     group: nextcloud
-#     state: link
-#     follow: false
+- name: Afficher les logs du script d'install
+  ansible.builtin.fail:
+    msg: "Le script d'install a échoué: Voir les logs ci-dessus"
+  when: install_result.failed
 
-# - name: Create sigle nextcloud config
-#   become_user: "{{ nextcloud_php_user }}"
-#   become: true
-#   ansible.builtin.template:
-#     src: templates/sigle.config.php.j2
-#     dest: "{{ nextcloud_webroot }}/config/sigle.config.php"
-#     owner: "{{ nextcloud_php_user }}"
-#     group: "{{ nextcloud_websrv_user }}"
-#     mode: '640' # or u=rwx,g=r,o=
+- name: Créer les fichiers spécifiques nextcloud
+  ansible.builtin.template:
+    src: "templates/{{ item.src }}"
+    dest: "{{ nextcloud_webroot }}/{{ item.dest }}"
+    owner: "{{ item.owner }}"
+    group: "{{ item.group }}"
+    mode: "{{ item.mode }}"
+  loop:
+    - src: "nextcloud_sigle_config.j2"
+      dest: "config/{{ SIGLE }}.config.php"
+      owner: "{{ nextcloud_php_user }}"
+      group: "{{ nextcloud_websrv_user }}"
+      mode: '640'
+
+- name: Creation d'un lien symbolique vers la configuration nextcloud common
+  ansible.builtin.file:
+    src: "../../../../nextcloud/common.config.php"
+    path: "{{ nextcloud_webroot }}/config/common.config.php"
+    owner: nextcloud
+    group: nextcloud
+    state: link
+    follow: false
 
-- name: Pour chaque base, ajouter les droits suivants à l'utilisateur php
-  become_user: postgres
-  become: true
-  community.postgresql.postgresql_privs:
-    db: "{{ item.db }}"
-    privs: "{{ item.privs }}"
-#     type: "{{ item.type |default(omit)}}"
-    objs: "{{ item.objs }}"
-    role: "{{ item.role }}"
-#     grant_option: "{{ item.grant_option |default(omit) }}"
-  loop_control:
-    label: "{{ item.name }}"
-  loop:
-    - db: "{{ nextcloud_db_name }}"
-      privs: "USAGE,CREATE"
-      type: "schema"
-      objs: "public"
-      role: "{{ nextcloud_php_user }}"
-      name: "GRANT USAGE,CREATE ON SCHEMA public TO php_{{ SIGLE }}_nuage;"
-#     - db: "{{ nextcloud_db_name }}"
-#       privs: "SELECT"
-#       type: "table"
-#       objs: "pg_namespace"
-#       role: "{{ nextcloud_php_user }}"
-#       name: "GRANT SELECT ON TABLE pg_namespace TO php_{{ SIGLE }}_nuage;"
-#     - db: "{{ nextcloud_db_name }}"
-#       privs: "SELECT"
-#       type: "table"
-#       objs: "pg_collation"
-#       role: "{{ nextcloud_php_user }}"
-#       name: "GRANT SELECT ON TABLE pg_collation TO php_{{ SIGLE }}_nuage;"
-#     - db: "{{ nextcloud_db_name }}"
-#       privs: "SELECT"
-#       type: "table"
-#       objs: "pg_index"
-#       role: "{{ nextcloud_php_user }}"
-#       name: "GRANT SELECT ON TABLE pg_index TO php_{{ SIGLE }}_nuage;"
-#     - db: "{{ nextcloud_db_name }}"
-#       privs: "SELECT"
-#       type: "table"
-#       objs: "pg_attrdef"
-#       role: "{{ nextcloud_php_user }}"
-#       name: "GRANT SELECT ON TABLE pg_attrdef TO php_{{ SIGLE }}_nuage;"
-#     - db: "{{ nextcloud_db_name }}"
-#       privs: "SELECT"
-#       type: "table"
-#       objs: "pg_description"
-#       role: "{{ nextcloud_php_user }}"
-#       name: "GRANT SELECT ON TABLE pg_description TO php_{{ SIGLE }}_nuage;"
-#     - db: "{{ nextcloud_db_name }}"
-#       privs: "SELECT"
-#       type: "table"
-#       objs: "pg_settings"
-#       role: "{{ nextcloud_php_user }}"
-#       name: "GRANT SELECT ON TABLE pg_settings TO php_{{ SIGLE }}_nuage;"
-#     - db: "{{ nextcloud_db_name }}"
-#       privs: "SELECT"
-#       objs: "pg_database"
-#       role: "{{ nextcloud_php_user }}"
-#       name: "GRANT SELECT ON pg_database TO php_{{ SIGLE }}_nuage;"
+- name: Pour chaque base, ajouter les droits suivants à l'utilisateur php
+  become_user: postgres
+  become: true
+  community.postgresql.postgresql_privs:
+    db: "{{ item.db }}"
+    privs: "{{ item.privs }}"
+    type: "{{ item.type | default(omit) }}"
+    objs: "{{ item.objs }}"
+    role: "{{ item.role }}"
+    grant_option: "{{ item.grant_option | default(omit) }}"
+  loop_control:
+    label: "{{ item.name }}"
+  loop:
+    - db: "{{ nextcloud_db_name }}"
+      privs: "USAGE,CREATE"
+      type: "schema"
+      objs: "public"
+      role: "{{ nextcloud_php_user }}"
+      name: "GRANT USAGE,CREATE ON SCHEMA public TO php_{{ SIGLE }}_nuage;"
+    # - db: "{{ nextcloud_db_name }}"
+    #   privs: "SELECT"
+    #   type: "table"
+    #   objs: "pg_namespace"
+    #   role: "{{ nextcloud_php_user }}"
+    #   name: "GRANT SELECT ON TABLE pg_namespace TO php_{{ SIGLE }}_nuage;"
+    # - db: "{{ nextcloud_db_name }}"
+    #   privs: "SELECT"
+    #   type: "table"
+    #   objs: "pg_collation"
+    #   role: "{{ nextcloud_php_user }}"
+    #   name: "GRANT SELECT ON TABLE pg_collation TO php_{{ SIGLE }}_nuage;"
+    # - db: "{{ nextcloud_db_name }}"
+    #   privs: "SELECT"
+    #   type: "table"
+    #   objs: "pg_index"
+    #   role: "{{ nextcloud_php_user }}"
+    #   name: "GRANT SELECT ON TABLE pg_index TO php_{{ SIGLE }}_nuage;"
+    # - db: "{{ nextcloud_db_name }}"
+    #   privs: "SELECT"
+    #   type: "table"
+    #   objs: "pg_attrdef"
+    #   role: "{{ nextcloud_php_user }}"
+    #   name: "GRANT SELECT ON TABLE pg_attrdef TO php_{{ SIGLE }}_nuage;"
+    # - db: "{{ nextcloud_db_name }}"
+    #   privs: "SELECT"
+    #   type: "table"
+    #   objs: "pg_description"
+    #   role: "{{ nextcloud_php_user }}"
+    #   name: "GRANT SELECT ON TABLE pg_description TO php_{{ SIGLE }}_nuage;"
+    # - db: "{{ nextcloud_db_name }}"
+    #   privs: "SELECT"
+    #   type: "table"
+    #   objs: "pg_settings"
+    #   role: "{{ nextcloud_php_user }}"
+    #   name: "GRANT SELECT ON TABLE pg_settings TO php_{{ SIGLE }}_nuage;"
+    # - db: "{{ nextcloud_db_name }}"
+    #   privs: "SELECT"
+    #   objs: "pg_database"
+    #   role: "{{ nextcloud_php_user }}"
+    #   name: "GRANT SELECT ON pg_database TO php_{{ SIGLE }}_nuage;"
 
-# - name: Creation d'un fichier cron pour  /etc/cron.d
-  ansible.builtin.cron:
-#     name: "nextcloud {{ SIGLE }}_{{ SITE }} taches d'arriere plan "
-#     minute: "5"
-#     user: "php_{{ SIGLE}}_{{SITE}}"
-#     job: "{{ nextcloud_source }}/cron"
+- name: Creation d'un fichier cron pour /etc/cron.d
+  ansible.builtin.cron:
+    name: "nextcloud {{ SIGLE }}_{{ config_ss_domain }} taches d'arriere plan toutes les 5 mins"
+    minute: "*/5"
+    user: "php_{{ SIGLE }}_{{ config_ss_domain }}"
+    job: "{{ nextcloud_webroot }}/cron"
 
-# - name: Recharger plusieurs services
-#   ansible.builtin.service:
-#     name: "{{ item }}"
-#     state: reloaded
-#   loop:
-#     - "postgresql"
-#     - "php{{ php_version }}-fpm"
-#     - "nginx"
+- name: Recharger plusieurs services
+  ansible.builtin.service:
+    name: "{{ item }}"
+    state: reloaded
+  loop:
+    - "php{{ php_version }}-fpm"
+    - "nginx"