2024-04-22 02:27:48 +00:00
|
|
|
- name: Install MySQL module for Ansible
|
|
|
|
ansible.builtin.apt:
|
|
|
|
name: python3-pymysql
|
|
|
|
state: present
|
2020-07-11 07:38:45 +00:00
|
|
|
|
2024-04-22 02:27:48 +00:00
|
|
|
- name: Create Nextcloud database
|
|
|
|
community.mysql.mysql_db:
|
|
|
|
name: "{{ nextcloud.DB_NAME | default('nextcloud') }}"
|
|
|
|
state: present
|
|
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
2020-07-02 05:35:01 +00:00
|
|
|
|
2024-04-22 02:27:48 +00:00
|
|
|
- name: Create Nextcloud database user
|
|
|
|
community.mysql.mysql_user:
|
|
|
|
name: "{{ nextcloud.DB_USER | default('nextcloud') }}"
|
|
|
|
password: "{{ nextcloud.DB_PASSWD }}"
|
|
|
|
host: '%'
|
|
|
|
state: present
|
|
|
|
priv: "{{ nextcloud.DB_NAME | default('nextcloud') }}.*:ALL"
|
|
|
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
2020-07-02 05:35:01 +00:00
|
|
|
|
2024-04-22 02:27:48 +00:00
|
|
|
- name: Start Nextcloud service and enable on boot
|
|
|
|
ansible.builtin.service:
|
|
|
|
name: "{{ docker_compose_service }}@{{ nextcloud_name }}"
|
|
|
|
state: started
|
|
|
|
enabled: true
|
|
|
|
when: nextcloud.ENABLE | default('false')
|
2020-08-01 02:30:20 +00:00
|
|
|
|
2020-07-07 21:21:04 +00:00
|
|
|
- name: Grab Nextcloud container information
|
2023-05-04 03:42:55 +00:00
|
|
|
community.general.docker_container_info:
|
2024-04-22 02:27:48 +00:00
|
|
|
name: "{{ nextcloud_name }}"
|
2020-07-07 21:21:04 +00:00
|
|
|
register: nextcloud_info
|
|
|
|
|
|
|
|
- name: Wait for Nextcloud to become available
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.wait_for:
|
2020-07-11 07:38:45 +00:00
|
|
|
host: "{{ nextcloud_info.container.NetworkSettings.Networks.traefik.IPAddress }}"
|
2024-04-22 02:27:48 +00:00
|
|
|
delay: 10
|
2020-07-07 21:21:04 +00:00
|
|
|
port: 80
|
|
|
|
|
|
|
|
- name: Check Nextcloud status
|
2024-04-22 02:27:48 +00:00
|
|
|
ansible.builtin.command: >
|
|
|
|
docker exec --user www-data "{{ nextcloud_name }}" php occ status
|
2020-07-07 21:21:04 +00:00
|
|
|
register: nextcloud_status
|
2024-04-22 02:27:48 +00:00
|
|
|
changed_when: false
|
2020-08-01 02:30:20 +00:00
|
|
|
|
2020-07-07 21:21:04 +00:00
|
|
|
- name: Install Nextcloud
|
2024-04-22 02:27:48 +00:00
|
|
|
ansible.builtin.command: >
|
|
|
|
docker exec --user www-data {{ nextcloud_name }}
|
|
|
|
php occ maintenance:install
|
|
|
|
--database "mysql"
|
|
|
|
--database-host "{{ nextcloud.DB_HOST | default('host.docker.internal') }}"
|
|
|
|
--database-name "{{ nextcloud.DB_NAME | default('nextcloud') }}"
|
|
|
|
--database-user "{{ nextcloud.DB_USER | default('nextcloud') }}"
|
|
|
|
--database-pass "{{ nextcloud.DB_PASSWD }}"
|
|
|
|
--admin-user "{{ nextcloud.ADMIN_USER | default('admin') }}"
|
|
|
|
--admin-pass "{{ nextcloud.ADMIN_PASSWD }}"
|
2020-07-07 21:21:04 +00:00
|
|
|
register: nextcloud_install
|
2024-04-22 02:27:48 +00:00
|
|
|
when: nextcloud_status.stderr[:26] == "Nextcloud is not installed"
|
|
|
|
changed_when: nextcloud_install.stdout == "Nextcloud was successfully installed"
|
|
|
|
notify: install_nextcloud
|
2020-07-07 21:44:25 +00:00
|
|
|
|
2023-06-19 03:52:10 +00:00
|
|
|
- name: Install Nextcloud background jobs cron
|
|
|
|
ansible.builtin.cron:
|
|
|
|
name: Nextcloud background job
|
|
|
|
minute: "*/5"
|
|
|
|
job: "/usr/bin/docker exec -u www-data nextcloud /usr/local/bin/php -f /var/www/html/cron.php"
|
|
|
|
user: root
|