Handle multiple users inside a playbook

I have a playbook where I access as user without privigiles, then i become root with become: yes and --ask-become-pass.
At some point I have few task that require to be executed as another user (apache), for example:

  • name: Check if maintenance install is present
    shell: php occ | grep maintenance
    become: yes
    become_user: apache
    become_method: sudo
    args:
    chdir: “{{path_installation}}nextcloud/”
    register: maintenance_install

I tried to add the regular user to wheel group but it doesn’t work, because I thought that the script would have tried:

  • SSH access via regular user (i.e test);
  • Detection of the become method and become user indicated in the task
  • execution of the task by providing the password used for the regular user (i.e. test).

But it didn’t worked because, I suppose, it uses as become password the one given with --ask-become-password.

Any suggestion? How could I write the script?