---
# Script to run git_update_sellyoursaas.sh to update SellYourSaas on servers
#
# To run the script:
# ansible-playbook -K launch_git_update_sellyoursaas.yml -i hosts-xxx -e 'target=targethost'
# ansible-playbook -K launch_git_update_sellyoursaas.yml -i hosts-xxx -e 'target=targethost' --limit=*.mydomain.com

- name: Update SellYourSaas on servers
  hosts: '{{target}}'
  become: yes
  become_method: sudo
  become_user: admin
  tasks:
  - name: Launch git_update_sellyoursaas.sh
    command: /home/admin/wwwroot/dolibarr_sellyoursaas/scripts/git_update_sellyoursaas.sh /home/admin/wwwroot/
    register: command_output

  - debug:
      var: command_output.stdout_lines

  - name: Add upgrade.unlock
    ansible.builtin.file:
      path: "/home/admin/wwwroot/dolibarr_documents/upgrade.unlock"
      state: touch
      owner: "admin"
      group: "www-data"
      mode: "0660"
    register: command_output
    when: 
      - unlock is defined
      - "'master' in group_names"
      