ajout playbook creation site
[lhc/ansible.git] / tasks / config_paheko.yml
diff --git a/tasks/config_paheko.yml b/tasks/config_paheko.yml
new file mode 100644 (file)
index 0000000..904aff5
--- /dev/null
@@ -0,0 +1,145 @@
+- name: Install required packages
+  ansible.builtin.apt:
+    name:
+      - php
+      - php-sqlite3
+      - php-intl
+      - php-cli
+      - php-imagick
+      - php-mbstring
+    state: present
+  register: php_install
+
+- name: Enable PHP modules
+  ansible.builtin.command: phpenmod sqlite3 imagick intl
+  when: php_install.changed
+
+- name: Ajout de l'utilisateur php_SIGLE_SITE
+  ansible.builtin.user:
+    name: "php_{{ SIGLE }}_{{ SITE }}"
+    home: "/etc/php/{{ php_version }}/fpm/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}"
+    shell: /bin/false
+    system: true
+    append: true
+    create_home: false
+    password: '!'
+#    group: "php_{{ SIGLE }}_{{ SITE }}"
+
+- name: Bloc paheko_version
+  when: paheko_version is undefined
+  block:
+    - name: Demande la version de nextcloud à installer
+      ansible.builtin.pause:
+        prompt: "Quelle version de nextcloud doit être utilisé"
+        echo: true
+      register: paheko_version_prompt
+
+    - name: Definir paheko_version
+      ansible.builtin.set_fact:
+        paheko_version: "{{ paheko_version_prompt.user_input }}"
+
+- name: Vérif si la source paheko est téléchargée
+  become: true
+  ansible.builtin.stat:
+    path: "/home/sites/data/paheko/{{ paheko_version }}"
+  register: paheko_source_path
+
+- name: Installion de la nouvelle version paheko
+  when: not paheko_source_path.stat.exists
+  block:
+
+    - name: Boucle création ou modifications des répertoires pahéko
+      ansible.builtin.file:
+        path: "{{ item.path }}"
+        state: "{{ item.state }}"
+        owner: "{{ item.owner }}"
+        group: "{{ item.group }}"
+        mode: "{{ item.mode }}"
+      loop_control:
+        label: "{{ item.path }}"
+      loop:
+        - path: "/home/sites/data/paheko/{{ paheko_version }}"
+          state: "directory"
+          owner: "www-data"
+          group: "www-data"
+          mode: "755"
+
+    - name: Telecharger la source Paheko
+      become: true
+      become_user: www-data
+      ansible.builtin.get_url:
+        url: "https://fossil.kd2.org/paheko/uv/paheko-{{ paheko_version }}.tar.gz"
+        dest: "/home/sites/data/paheko/{{ paheko_version }}.tar.gz"
+        mode: '755' # or u=rwx,g=rx,o=rx
+
+    - name: Extract downloaded nextcloud source
+      become: true
+      become_user: www-data
+      ansible.builtin.unarchive:
+        src: "/home/sites/data/paheko/{{ paheko_version }}.tar.gz"
+        dest: "/home/sites/data/paheko"
+    #    mode: '755' # or u=rwx,g=rx,o=rx
+        remote_src: true
+
+    - name: Renommer paheko-version par uniquement la version
+      become: true
+      become_user: www-data
+      ansible.builtin.copy:
+        src: "/home/sites/data/paheko/paheko-{{ paheko_version }}/"
+        dest: "/home/sites/data/paheko/{{ paheko_version }}"
+        remote_src: true # because the config file is already in the nextcloud_tmp_path
+        mode: preserve
+
+    - name: Deleted downloaded nextcloud files
+      become: true
+      ansible.builtin.file:
+        path: "{{ item }}"
+        state: absent
+      loop:
+        - "/home/sites/data/paheko/{{ paheko_version }}.tar.gz"
+        - "/home/sites/data/paheko/paheko-{{ paheko_version }}"
+
+- name: Copie la source paheko vers le home du site
+  become: true
+#  become_user: "php_{{ SIGLE }}_{{ SITE }}"
+  ansible.builtin.copy:
+    src: "/home/sites/data/paheko/{{ paheko_version }}/"
+    dest: "/home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}"
+    remote_src: true # because the config file is already in the nextcloud_tmp_path
+
+- name: Modification du propriétaire group et droits du dossier
+  ansible.builtin.file:
+    path: "/home/sites/data/{{ TLD }}/{{ DOMAIN }}/{{ SITE }}/"
+    state: directory
+    owner: "php_{{ SIGLE }}_{{ SITE }}"
+    group: "php_{{ SIGLE }}_{{ SITE }}"
+    mode: '644'
+    recurse: true
+
+- name: Boucle d'ajout du user php dans plusieurs groupe
+  ansible.builtin.user:
+    name: "php_{{ SIGLE }}_{{ SITE }}"
+    groups: "{{ item }}"
+    append: true
+  loop:
+    - "site_{{ SIGLE }}_{{ SITE }}"
+
+# - name: Change displayed icon
+#   ansible.builtin.copy:
+#     src: "{{ icon }}"
+#     dest: "/usr/share/garradin/www/admin/static/icon{{ icon | splitext | last }}"
+#   when: icon is defined
+
+# - name: Change page favicon
+#   ansible.builtin.copy:
+#     src: "{{ favicon }}"
+#     dest: "/usr/share/garradin/www/admin/static/favicon{{ icon | splitext | last }}"
+#   when: favicon is defined
+
+- name: Recharger PHP service
+  ansible.builtin.service:
+    name: "{{ item }}"
+    state: reloaded
+  loop:
+    - "php{{ php_version }}-fpm"
+    - "nginx"