Hi!
I've split some tasks in two roles, one with plays requiring sudo and
the other with plays not requiring it (hence run as 'ubuntu').
I have a top level playbook that maps the same group of hosts to both
roles, the first enabling sudo, the second disabling it, like this:
site.yml:
The issue looks you are dealing with cached facts, if you remove the sudo
from the play level and set it at the somerole-sudo level (or have previous
play/task w/o sudo gather_facts) you'll get the user you expect.
Also you can force new facts to be gathered in the 2nd play with gather_facts: True. The implicit version uses the cache, the explicit will actually force a fact gathering.
It makes sense. I've tried both methods you propose and in both cases
it works like a charm.
Thanks a lot, Brian!
Happy hacking,