Skip to content

Commit

Permalink
Merge pull request #329 from l00ptr/fix-naming-tasks
Browse files Browse the repository at this point in the history
Rename tasks to be closer to Ansible convention
  • Loading branch information
staticdev authored Dec 31, 2023
2 parents 1bdaae8 + 8947b79 commit 35e87e2
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 115 deletions.
30 changes: 15 additions & 15 deletions roles/install_nextcloud/tasks/db_mysql.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
---
- name: "[mySQL] - Service is installed."
- name: db_mysql | Service is installed
ansible.builtin.package:
name: "{{ 'default-' if ((ansible_distribution | lower) == 'debian' and nextcloud_db_backend == 'mysql') else '' }}{{ nextcloud_db_backend }}-server"
state: present
register: nc_mysql_db_install

- name: "[mySQL] - Check if MySQL packages were installed."
- name: db_mysql | Check if MySQL packages were installed
ansible.builtin.set_fact:
mysql_install_packages: "{{ nc_mysql_db_install is defined and nc_mysql_db_install.changed }}"

- name: "[mySQL] - Get MySQL version."
- name: db_mysql | Get MySQL version
ansible.builtin.command: 'mysql --version'
register: mysql_cli_version
changed_when: false
check_mode: false

- name: "[mySQL] - Packages are installed."
- name: db_mysql | Install packages for MySQL
ansible.builtin.package:
name: "{{ nc_mysql_deps }}"
state: present
vars:
nc_mysql_deps:
- "python3-pymysql"

- name: "[mySQL] - Ensure MySQL is started and enabled on boot."
- name: db_mysql | Ensure MySQL is started and enabled on boot
ansible.builtin.service:
name: "{{ mysql_daemon }}"
state: started
enabled: "{{ nextcloud_db_enabled_on_startup }}"
register: mysql_service_configuration

- name: "[mySQL] - Get list of hosts for the root user."
- name: db_mysql | Get list of hosts for the root user
ansible.builtin.command: mysql -NBe
"SELECT Host
FROM mysql.user
Expand All @@ -43,7 +43,7 @@

# Note: We do not use mysql_user for this operation, as it doesn't always update
# the root password correctly. See: https://goo.gl/MSOejW
- name: "[mySQL] - Update MySQL root password for localhost root account (5.7.x)."
- name: db_mysql | Update MySQL root password for localhost root account (5.7.x)
ansible.builtin.shell: >
mysql -u root -NBe
'ALTER USER "root"@"{{ item }}"
Expand All @@ -55,7 +55,7 @@
register: output
changed_when: "output.rc == 0"

- name: "[mySQL] - Update MySQL root password for localhost root account (< 5.7.x)."
- name: db_mysql | Update MySQL root password for localhost root account (< 5.7.x)
ansible.builtin.shell: >
mysql -NBe
'SET PASSWORD FOR "root"@"{{ item }}" = PASSWORD("{{ nextcloud_mysql_root_pwd }}"); FLUSH PRIVILEGES;'
Expand All @@ -66,7 +66,7 @@
register: output
changed_when: "output.rc == 0"

- name: "[mySQL] - Copy .my.cnf file with root password credentials."
- name: db_mysql | Copy .my.cnf file with root password credentials
ansible.builtin.template:
src: "root-my.cnf.j2"
dest: "/root/.my.cnf"
Expand All @@ -75,40 +75,40 @@
mode: 0600
when: mysql_install_packages | bool or nextcloud_mysql_root_pwd_update

- name: "[mySQL] - Get list of hosts for the anonymous user."
- name: db_mysql | Get list of hosts for the anonymous user
ansible.builtin.command: mysql -NBe 'SELECT Host FROM mysql.user WHERE User = ""'
register: mysql_anonymous_hosts
changed_when: false
check_mode: false

- name: "[mySQL] - Remove anonymous MySQL users."
- name: db_mysql | Remove anonymous MySQL users
community.mysql.mysql_user:
name: ""
host: "{{ item }}"
state: absent
with_items: "{{ mysql_anonymous_hosts.stdout_lines | default([]) }}"

- name: "[mySQL] - Remove MySQL test database."
- name: db_mysql | Remove MySQL test database
community.mysql.mysql_db:
name: 'test'
state: absent

- name: "[mySQL] - Set mysql config option for Nextcloud"
- name: db_mysql | Set mysql config option for Nextcloud
ansible.builtin.copy:
dest: /etc/mysql/conf.d/nextcloud.cnf
src: files/mysql_nextcloud.cnf
mode: 0600
notify: Restart mysql

- name: "[mySQL] - Add Database {{ nextcloud_db_name }}"
- name: db_mysql | Add Database {{ nextcloud_db_name }}"
community.mysql.mysql_db:
name: "{{ nextcloud_db_name }}"
login_user: root
login_password: "{{ nextcloud_mysql_root_pwd }}"
config_file: "{{ mysql_credential_file[(ansible_os_family | lower)] | default(omit) }}"
state: present

- name: "[mySQL] - Configure the database user."
- name: db_mysql | Configure the database user
community.mysql.mysql_user:
name: "{{ nextcloud_db_admin }}"
password: "{{ nextcloud_db_pwd }}"
Expand Down
6 changes: 3 additions & 3 deletions roles/install_nextcloud/tasks/db_postgresql.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: "[PostgreSQL] - PostgreSQL packages are installed"
- name: db_postgresql | Install PostgreSQL packages
ansible.builtin.package:
name: "{{ pg_deps }}"
state: "present"
Expand All @@ -8,7 +8,7 @@
- "postgresql"
- "python3-psycopg2"

- name: "[PostgreSQL] - nextcloud role is created."
- name: db_postgresql | Create PostgreSQL Nextcloud role
community.postgresql.postgresql_user:
name: "{{ nextcloud_db_admin }}"
password: "{{ nextcloud_db_pwd }}"
Expand All @@ -18,7 +18,7 @@
become_user: postgres
become: true

- name: "[PostgreSQL] - nextcloud database is created."
- name: db_postgresql | Create PostgreSQL Nextcloud database
community.postgresql.postgresql_db:
name: "{{ nextcloud_db_name }}"
state: present
Expand Down
14 changes: 7 additions & 7 deletions roles/install_nextcloud/tasks/http_apache.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: "[APACHE] - enable APC for php CLI"
- name: http_apache | Enable APC for php CLI
ansible.builtin.lineinfile:
dest: "{{ php_dir }}/cli/php.ini"
line: "apc.enable_cli = 1"
insertbefore: "^; End:$"
state: present
# validate: "/usr/sbin/{{ php_bin }} -t #%s"

- name: "[APACHE] - enable PHP OPcache for php.ini"
- name: http_apache | Enable PHP OPcache for php.ini
ansible.builtin.lineinfile:
dest: "{{ php_dir }}/apache2/php.ini"
state: present
Expand All @@ -26,7 +26,7 @@
# validate: "/usr/sbin/{{ php_bin }} -t #%s"
notify: Reload http

- name: "[APACHE] - Required Apache2 modules are enabled"
- name: http_apache | Enable required Apache2 modules
community.general.apache2_module:
name: "{{ item }}"
state: present
Expand All @@ -38,7 +38,7 @@
- mime
notify: Restart http

- name: "[APACHE] - Ssl Apache2 module is enabled"
- name: http_apache | Enable ssl Apache2 module
community.general.apache2_module:
state: present
name: "{{ item }}"
Expand All @@ -47,21 +47,21 @@
when: (nextcloud_install_tls | bool)
notify: Restart http

- name: "[APACHE] - generate Nextcloud configuration for apache"
- name: http_apache | Generate Nextcloud configuration for apache
ansible.builtin.template:
dest: /etc/apache2/sites-available/nc_{{ nextcloud_instance_name }}.conf
src: "{{ nextcloud_websrv_template }}"
mode: 0640
notify: Reload http

- name: "[APACHE] - Enable Nextcloud site in apache conf"
- name: http_apache | Enable Nextcloud site in apache conf
ansible.builtin.file:
path: /etc/apache2/sites-enabled/nc_{{ nextcloud_instance_name }}.conf
src: /etc/apache2/sites-available/nc_{{ nextcloud_instance_name }}.conf
state: link
notify: Reload http

- name: "[APACHE] - Disable apache default site"
- name: http_apache | Disable apache default site
ansible.builtin.file:
path: /etc/apache2/sites-enabled/000-default.conf
state: absent
Expand Down
20 changes: 10 additions & 10 deletions roles/install_nextcloud/tasks/http_nginx.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: "[NGINX] - remove some commented line in php-fpm conf"
- name: http_nginx | Remove some commented line in php-fpm conf
ansible.builtin.lineinfile:
dest: "{{ php_dir }}/fpm/pool.d/www.conf"
regexp: '^\;env'
state: absent
# validate: "/usr/sbin/{{ php_bin }} -t #%s"
notify: Reload php-fpm

- name: "[NGINX] - Add path variable to php-fpm"
- name: http_nginx | Add path variable to php-fpm
ansible.builtin.blockinfile:
dest: "{{ php_dir }}/fpm/pool.d/www.conf"
insertafter: '^; Default Value: clean env$'
Expand All @@ -20,7 +20,7 @@
env[TEMP] = /tmp
notify: Reload php-fpm

- name: "[NGINX] - enable APC for php CLI"
- name: http_nginx | Enable APC for php CLI
ansible.builtin.lineinfile:
dest: "{{ php_dir }}/cli/php.ini"
line: "apc.enable_cli = 1"
Expand All @@ -29,7 +29,7 @@
# validate: "/usr/sbin/{{ php_bin }} -t #%s"
notify: Reload php-fpm

- name: "[NGINX] - enable PHP OPcache for php.ini"
- name: http_nginx | Enable PHP OPcache for php.ini
ansible.builtin.lineinfile:
dest: "{{ php_dir }}/fpm/php.ini"
state: present
Expand All @@ -49,40 +49,40 @@
notify: Reload php-fpm


- name: "[NGINX] - Public Diffie-Hellman Parameter are generated. This might take a while."
- name: http_nginx | Generate Public Diffie-Hellman parameter (This might take a while)
ansible.builtin.command: "openssl dhparam -out {{ nextcloud_tls_dhparam }} 2048"
args:
creates: "{{ nextcloud_tls_dhparam }}"

- name: "[NGINX] - php handler configuration is present."
- name: http_nginx | Configure php handler
ansible.builtin.template:
dest: /etc/nginx/sites-available/php_handler.cnf
src: templates/nginx_php_handler.j2
mode: 0640
notify: Reload http

- name: "[NGINX] - php handler is enabled"
- name: http_nginx | Enable php handler
ansible.builtin.file:
path: /etc/nginx/sites-enabled/php_handler
src: /etc/nginx/sites-available/php_handler.cnf
state: link
notify: Reload http

- name: "[NGINX] - generate Nextcloud configuration for nginx"
- name: http_nginx | Generate Nextcloud configuration for nginx
ansible.builtin.template:
dest: /etc/nginx/sites-available/nc_{{ nextcloud_instance_name }}.cnf
src: "{{ nextcloud_websrv_template }}"
mode: 0640
notify: Reload http

- name: "[NGINX] - Enable Nextcloud in nginx conf"
- name: http_nginx | Enable Nextcloud in nginx conf
ansible.builtin.file:
path: /etc/nginx/sites-enabled/nc_{{ nextcloud_instance_name }}
src: /etc/nginx/sites-available/nc_{{ nextcloud_instance_name }}.cnf
state: link
notify: Reload http

- name: "[NGINX] - Disable nginx default site"
- name: http_nginx | Disable nginx default site
ansible.builtin.file:
path: /etc/nginx/sites-enabled/default
state: absent
Expand Down
16 changes: 8 additions & 8 deletions roles/install_nextcloud/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
# tasks file for nextcloud

- name: "Load os specific variables"
- name: Load os specific variables
ansible.builtin.include_tasks: ./setup_env.yml
tags:
- install_apps

- name: "Install PHP packages"
- name: Install PHP packages
ansible.builtin.include_tasks: php_install.yml
tags:
- install_apps
Expand Down Expand Up @@ -91,7 +91,7 @@
- install_apps
- patch_user_saml_app
block:
- name: "[NC apps] - lists the number of apps available in the instance."
- name: Lists the number of apps available in the instance
ansible.builtin.command: php occ app:list --output=json_pretty --no-warnings
args:
chdir: "{{ nextcloud_webroot }}"
Expand All @@ -102,11 +102,11 @@
check_mode: false
register: nc_apps_list

- name: "[NC apps] - convert list to yaml."
- name: Convert list to yaml
ansible.builtin.set_fact:
nc_available_apps: "{{ nc_apps_list.stdout | from_json }}"

- name: "[NC apps] - installation."
- name: Install apps
ansible.builtin.include_tasks: ./nc_apps.yml
# do if the app is not enabled and ( (archive path is not "") or (app is disabled) )
when:
Expand All @@ -126,7 +126,7 @@
changed_when: '"Done" not in nc_indices_cmd.stdout'
when: nextcloud_install_db

- name: "[Main] - Patch from the app 'user_saml' the file SAMLController.php."
- name: Main | Patch from the app 'user_saml' the file SAMLController.php
when:
- nextcloud_patch_user_saml_app
- nc_available_apps.enabled['user_saml'] is defined or nc_available_apps.disabled['user_saml'] is defined
Expand All @@ -136,12 +136,12 @@
pattern: '.*\$this->session->set\(.user_saml\.samlUserData.,\s+\$_SERVER\);.*'
file2patch: "{{ nextcloud_webroot + '/apps/user_saml/lib/Controller/SAMLController.php' }}"
block:
- name: "[Main] - Check if SAMLController.php can be patched."
- name: Main | Check if SAMLController.php can be patched
ansible.builtin.slurp:
src: "{{ file2patch }}"
register: df_file

- name: "[Main] - Patch file SAMController.php."
- name: Main | Patch file SAMController.php
ansible.builtin.blockinfile:
block: "{{ lookup('ansible.builtin.file', 'files/SAMLController.patch') }}"
path: "{{ file2patch }}"
Expand Down
12 changes: 6 additions & 6 deletions roles/install_nextcloud/tasks/nc_apps.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
- name: "[App] - Parse the item values"
- name: nc_apps | Parse the item values
ansible.builtin.set_fact:
nc_app_name: "{{ item.key }}"
nc_app_source: "{{ item.value.source if item.value.source is defined else item.value }}"
nc_app_cfg: "{{ item.value }}"

- name: "[App] - Verify the yaml declaration for the app \"{{ nc_app_name }}\""
- name: "nc_apps | Verify the yaml declaration for the app \"{{ nc_app_name }}\""
ansible.builtin.assert:
that:
- (nc_app_cfg.source is defined) and (nc_app_cfg.source is string)
msg: "{{ nc_app_name }} is not well declared."
when: nc_app_cfg is not string

- name: "[App] - Install from the official app-store app: \"{{ nc_app_name }}\""
- name: "nc_apps | Install from the official app-store app: \"{{ nc_app_name }}\""
become_user: "{{ nextcloud_websrv_user }}"
become_flags: "{{ ansible_become_flags | default(omit) }}"
become: true
Expand All @@ -25,7 +25,7 @@
register: output
changed_when: "output.rc == 0"

- name: "[App] - Download or copy Archive to apps folder from \"{{ nc_app_source }}\""
- name: "nc_apps | Download or copy Archive to apps folder from \"{{ nc_app_source }}\""
become_user: "{{ nextcloud_websrv_user }}"
become_flags: "{{ ansible_become_flags | default(omit) }}"
ansible.builtin.unarchive:
Expand All @@ -39,7 +39,7 @@
- (nc_app_source is string) and (nc_app_source | length > 0)
- nc_app_name not in nc_available_apps.disabled

- name: "[App] - Enable the application \"{{ nc_app_name }}\""
- name: "nc_apps | Enable the application \"{{ nc_app_name }}\""
become_user: "{{ nextcloud_websrv_user }}"
become_flags: "{{ ansible_become_flags | default(omit) }}"
become: true
Expand All @@ -48,7 +48,7 @@
chdir: "{{ nextcloud_webroot }}"
changed_when: true

- name: "[App] - Configure the application \"{{ nc_app_name }}\""
- name: "nc_apps | Configure the application \"{{ nc_app_name }}\""
become_user: "{{ nextcloud_websrv_user }}"
become_flags: "{{ ansible_become_flags | default(omit) }}"
become: true
Expand Down
Loading

0 comments on commit 35e87e2

Please sign in to comment.