---
- hosts: all
  tasks:
    - name: "update git url"  
      become: true
      become_user: root
      command:
        cmd: "git remote set-url origin ssh://git@gitea.mewissen.site:22422/rene/dotfiles.git"
        chdir: "{{ ansible_user_dir }}/dotfiles"
    - name: "git default settings"
      become: true
      become_user: root
      command:
        cmd: "git config pull.rebase false"
        chdir: "{{ ansible_user_dir }}/dotfiles"
    # - name: "git pull"
    #   become: yes
    #   command:
    #     cmd: "git pull"
    #     chdir: "{{ ansible_user_dir }}/dotfiles"
    - name: "remove cronjob for ansible"
      become: false
      cron:
        name: "ansible provision"
        user: "{{ ansible_user_id }}"
        job: 'ansible-pull --vault-password-file=~/.vaultpass -U "https://gitea.mewissen.site/rene/ansible-pull.git" -d "/opt/ansible-pull" -C master > /var/log/ansible_update.log || cat /var/log/ansible_update.log'
        state: present
        minute: 0
        hour: 1
    - name: "add cronjob for ansible"
      become: true
      become_user: root
      cron:
        name: "ansible provision"
        user: "{{ ansible_user_id }}"
        job: 'ansible-pull --vault-password-file=~/.vaultpass -U "https://gitea.mewissen.site/rene/ansible-pull.git" -d "/opt/ansible-pull" -C master > /var/log/ansible_update.log || cat /var/log/ansible_update.log'
        state: present
        minute: 0
        hour: 1
    # - name: "update ansible-pull once"
    #   become: true
    #   become_user: root
    #   command:
    #     cmd: 'ansible-pull --vault-password-file=~/.vaultpass -U "https://gitea.mewissen.site/rene/ansible-pull.git" -d "/opt/ansible-pull" -C master'