- hosts: core no_log: yes tasks: - name: Run occ user:resetpassword. shell: | spawn sudo -u www-data \ /usr/bin/php occ user:resetpassword {{ user }} expect { "Enter a new password:" {} timeout { exit 1 } } send "{{ pass|quote }}\n" expect { "Confirm the new password:" {} timeout { exit 2 } } send "{{ pass|quote }}\n" expect { "Successfully reset password for {{ user }}" {} "Please choose a different password." { exit 3 } timeout { exit 4 } } args: chdir: /var/www/nextcloud/ executable: /usr/bin/expect