If you pass the variable as ansible_ssh_user instead of "remote_user" it
should do what you request, however, this is more idiomatic:
- hosts: ansible-localhost
remote_user: root
tasks:
- include: tasks/some_tasks.yml
- hosts: ansible-localhost
remote_user: toto
- include: tasks/some_other_tasks_to_be_run_with_user_toto.yml
On Tue, Apr 29, 2014 at 10:03 AM, A. J. <[email protected]> wrote:
> thanks for the quick answer.
> I think I did not express myself properly:
>
> I was actually wondering how to change the remote (user) when executing an
> included tasks file.
>
> My playbook already defines the remote_user (root), but I just want to run
> one of my included tasks as another user:
>
> - hosts: ansible-localhost
> remote_user: root
>
> tasks:
>
> - include: tasks/some_tasks.yml
>
> - include: tasks/some_other_tasks_to_be_run_with_user_toto.yml
> remote_user: toto
>
> The goal would be to avoid to repeat the "remote_user" for all the tasks
> in my included file:
>
> ---
>
> - name: task 1
> remote_user: toto
> sometask: ...
> - name: task 2
> remote_user: toto
> sometask2: ...
> - name: task 3
> remote_user: toto
> sometask3: ...
>
> ...
>
> thanks a lot for your time
> regards,
> ozb
>
>
> On Tuesday, April 29, 2014 2:31:12 PM UTC+2, Michael DeHaan wrote:
>
>> While a keyword in ansible for a task or play, remote_user is not a magic
>> variable here any more than "antelope_jetpack" is likely to work. It's
>> just the wrong variable name is all :)
>>
>> You can set "ansible_ssh_user" in inventory as a variable to control the
>> remote user, which could also be set here.
>>
>> Generally people set this at play level instead.
>>
>> - hosts: postgresql_steps
>> remote_user: postgres
>>
>> Etc
>>
>> Though usually most people would do this kind of thing with "sudo_user"
>> instead, and just pass the connecting user on the command line or assume
>> the default.
>>
>>
>>
>>
>>
>>
>> On Tue, Apr 29, 2014 at 3:31 AM, A. J. <[email protected]> wrote:
>>
>>> Hi, I'm new to ansible and have been unable to achieve the following:
>>> I would like to include tasks in my playbook and run them with another
>>> user that's running the playbook.
>>>
>>> I have tried the following, without success:
>>>
>>> - include: mytasks.yml remote_user=toto
>>>
>>> I have also tried this (from the documentation)
>>>
>>> - include: mytasks.yml
>>> vars:
>>> remote_user: toto
>>>
>>> but again, when running the playbook, the tasks are executed with the
>>> playbook remote user and not the one defined next to the include.
>>>
>>> I'm using ansible 1.5.4.
>>>
>>> Is there anyway to do this ? or do I have to specify the remote_user for
>>> each and every task in the tasks file ?
>>> thanks a lot,
>>> regards,
>>> ozb.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ansible Project" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>>
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/ansible-project/2487b810-9643-46a7-9f70-
>>> 1444e2670051%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/2487b810-9643-46a7-9f70-1444e2670051%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/581a7f02-ca98-448a-a602-40ca3882798b%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/581a7f02-ca98-448a-a602-40ca3882798b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgzciR6VzahRvNAQPReWrF-zdFoub8cvTH5KOaLxGbOk5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.