Thanks Mark,
This trick worked for me:
- name: vncserver command
shell: sudo -u {{ item.name }} -i vncserver </tmp/file >/tmp/vncpasswd.1
2>/tmp/vncpasswd.2
with_items:
vnc_users
The modification with your tick is only "i":
-i [command]
The -i (simulate initial login) option runs the shell
specified in the passwd(5)
entry of the target user as a login shell. This means
that login-specific resource
files such as .profile or .login will be read by the
shell. If a command is
specified, it is passed to the shell for execution.
Otherwise, an interactive shell
is executed. sudo attempts to change to that user's
home directory before running
the shell. It also initializes the environment, leaving
DISPLAY and TERM unchanged,
setting HOME, MAIL, SHELL, USER, LOGNAME, and PATH, as
well as the contents of
/etc/environment on Linux and AIX systems. All other
environment variables are
removed.
On Tuesday, February 3, 2015 at 10:55:51 PM UTC+5, Mark McCoy wrote:
>
> I think if fails because the command runs as the first user (or as root)
> and subsequent users can write to the output files in /tmp. Try this:
>
> - name: vncserver command
> shell: vncserver </tmp/file >"/tmp/vncpasswd.{{item}}.1" 2>"/tmp/
> vncpasswd.{{item}}.2"
> remote_user: "{{ item }}"
> sudo: False
> with_items:
> vnc_users
>
> ----
> Mark McCoy <http://markmccoy.us>
>
>
> On Tue, Feb 3, 2015 at 11:32 AM, Arbab Nazar <[email protected]
> <javascript:>> wrote:
>
>> Thanks, I have tried this and it worked partially. partially mean that
>> for each user in the list, I need to setup the ssh key plus sudo access (I
>> have tried it even without sudo but didn't work) but for some user I don't
>> want to give sudo access but if I didn't give sudo access then the task
>> fail :(
>>
>> - name: vncserver command
>> shell: vncserver </tmp/file >/tmp/vncpasswd.1 2>/tmp/vncpasswd.2
>> remote_user: "{{ item }}"
>> sudo: False
>> with_items:
>> vnc_users
>>
>> Thanks in advance
>>
>> On Tuesday, February 3, 2015 at 7:23:24 PM UTC+5, [email protected]
>> wrote:
>>>
>>> Hi,
>>>
>>> Are you saying to want to run the 'vncserver' command as each user? Does
>>> this work:
>>>
>>> - name: VNC | vncserver command
>>> shell: sudo -u {{item}} vncserver </tmp/file >/tmp/vncpasswd.1 2>
>>> /tmp/vncpasswd.2
>>> with_items:
>>> vnc_users
>>>
>>> What have you tried so far, and what were the results?
>>>
>>> On Monday, 2 February 2015 16:49:58 UTC, Arbab Nazar wrote:
>>>>
>>>> Hi I am new to ansible and stuck here, where i want to run this same
>>>> command but using the each user from the list.
>>>>
>>>> for example:
>>>>
>>>> in vars/main.yml
>>>> vpc_users:
>>>> - abc
>>>> - xyz
>>>> - qes
>>>>
>>>> in tasks/main.yml
>>>> - name: VNC | vncserver command
>>>> shell: vncserver </tmp/file >/tmp/vncpasswd.1 2>/tmp/vncpasswd.2
>>>> remote_user/sudo_user or somethine else?
>>>> with_items:
>>>> vnc_users
>>>>
>>>> Thanks in advance
>>>>
>>> --
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/2161b393-3003-4a63-813e-48cd1c038b3d%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/2161b393-3003-4a63-813e-48cd1c038b3d%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/8041c5ff-6170-4ee2-8187-b9d8351ed0a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.