---
title: "Mise à jour de Nextcloud docker par Ansible"
summary: "brief decription to sum up"
author:
  - JF
date: 2023-10-01
---
# Mise à jour de Nextcloud docker par Ansible

## Prérequis
[Se connecter en SSH au Synology à l’aide d’une clef asymétrique.](../Synology/2019-09-01-access-synology-with-ssh-asymetrical-key.md)

## Le playbook
```yaml
---
- name: Mise à jour du conteneur Nextcloud
  hosts: savaneprod.fr
  vars:
    nc_version: 28.0.5
  tasks:
    - name: Modification de la versions dans le  docker-compose
      ansible.builtin.lineinfile:
        path: /volume1/nextcloud/docker-compose.yaml
        backrefs: true
        backup: false
        state: present
        regexp: "^    image: nextcloud:"
        line: "    image: nextcloud:{{ nc_version }}"

    - name: "Téléchargement de l'image nextcloud: {{ nc_version }}"
      community.docker.docker_image:
      # Needed on DSM : pip3 install docker
        name: nextcloud
        source: pull
        tag: '{{ nc_version }}'

    - name: Compose down & compose up detached
      # Needed on DSM : pip3 install docker-compose
      community.docker.docker_compose:
        project_src: "/volume1/nextcloud"
        recreate: smart

    - name: Pause en attendant la remontée des conteneurs
      ansible.builtin.pause:
        #minutes: 2
        seconds: 30

    - name: "Mise à jour de la base de données"
      community.docker.docker_container_exec:
        container: nextcloud_app_1
        tty: true
        user: www-data
        command: "{{ item }}"
      loop:
        - "php occ db:add-missing-columns"
        - "php occ db:add-missing-indices"
        - "php occ db:add-missing-primary-keys"
        - "php occ config:system:set maintenance_window_start --type=integer --value=1"

    - name: Pause de 1 minute
      ansible.builtin.pause:
        minutes: 1

    - name: Modification du fichier .htaccess pour Mac
      tags: caldav
      ansible.builtin.lineinfile:
        path: /volume1/nextcloud/data/.htaccess
        backup: false
        state: present
        search_string: "{{ item.search_string }}"
        line: "{{ item.line }}"
      loop:
        - { search_string: 'RewriteRule ^\.well-known/carddav', line: '  RewriteRule ^\.well-known/carddav https://%{SERVER_NAME}/remote.php/dav/ [R=301,L]' }
        - { search_string: 'RewriteRule ^\.well-known/caldav', line: '  RewriteRule ^\.well-known/caldav https://%{SERVER_NAME}/remote.php/dav/ [R=301,L]' }

```
=> Cette façon de faire renvoi un problème d'intégrité sur le fichier config.php.
