Re: Some user of ansible_user

41 views
Skip to first unread message
Message has been deleted
Message has been deleted

Zolvaring

unread,
Aug 21, 2019, 2:40:11 AM8/21/19
to Ansible Project
I'm confused what you want to do when you use a second user. If you want fallback users, I don't know of a simple built in way but have gotten it to work looping user/pass /key combos with gather facts or a shell "sudo -l" command and register. Then loop through your registered var with set_facts and it's possible to set for each host the first successful credential set that worked before continuing the play.

If you want different tasks to be run with different users you can use become and become_user.

Zolvaring

unread,
Aug 21, 2019, 2:47:05 AM8/21/19
to Ansible Project
Ah I missed your detail about serial usage, but am not sure how you could do that. You could import or include a play with some sort of loop, or maybe registering a var after the final task and setting ansible_ssh_user to that var if it exists prior to the first task?

Karther

unread,
Aug 21, 2019, 4:33:07 AM8/21/19
to Ansible Project
Hey,

I thinks you have not understand.

I have my inventory host with this content :

my_host_1   ansible_user=wildfly
my_host_1   ansible_user=toto

When i play my playbook, ansible run playbook only on the first line my_host_1   ansible_user=wildfly and not on the second line.
So, same when i use serial: 1 in my playbook, ansible run only the first line.

I think ansible refers only to the host name and does not execute every line of my inventory ...?

Do you have any solution please for me community ansible !!! :)

Regards,

Mark Anthony Garcia

unread,
Aug 21, 2019, 4:44:47 AM8/21/19
to Ansible Project
For me I use the local users from the ansible controllers by calling the "{{ lookup('env','USER') }}".

On Tuesday, August 20, 2019 at 5:00:33 PM UTC+2, Karther wrote:
Hey,

I want to know if possible use a lot of user for ansible.

Exemple, if i use ansible_user=user1, user2

because i want to use serial: 1 

And i want that ansible use firt user1 and secondaly user2

If possible or not please ??

Regards,

Dick Visser

unread,
Aug 21, 2019, 6:13:10 AM8/21/19
to ansible...@googlegroups.com
On Wed, 21 Aug 2019 at 10:33, Karther <ryadmo...@gmail.com> wrote:
>
> Hey,
>
> I thinks you have not understand.
>
> I have my inventory host with this content :
>
> my_host_1 ansible_user=wildfly
> my_host_1 ansible_user=toto
>
> When i play my playbook, ansible run playbook only on the first line my_host_1 ansible_user=wildfly and not on the second line.
> So, same when i use serial: 1 in my playbook, ansible run only the first line.
>
> I think ansible refers only to the host name and does not execute every line of my inventory ...?

Ansible doesn't "execute lines of the inventory", it executes plays in
a playbook.
The inventory is to list the hosts you are targeting, so in this case
a single host.
Just have your inventory look like:

my_host_1

And then iterate over your play(s), using a different value for ansible_user.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Karther

unread,
Aug 21, 2019, 7:35:54 AM8/21/19
to Ansible Project
Hey Mark,

Ok for this issue, but my user of my environnement is different of my ansible_user of my inventory_hostname.

I have my inventory host with this content :

my_host_1   ansible_user=wildfly
my_host_1   ansible_user=toto

Ansible is my user of my environnement ....

Thanks for your help community ansible !! :)

Regards,

Stefan Hornburg (Racke)

unread,
Aug 21, 2019, 7:43:19 AM8/21/19
to ansible...@googlegroups.com
On 8/21/19 1:35 PM, Karther wrote:
> Hey Mark,
>
> Ok for this issue, but my user of my environnement is different of my ansible_user of my inventory_hostname.
>
> I have *my inventory host* with this content :
>
> my_host_1   ansible_user=wildfly
> my_host_1   ansible_user=toto
>
> Ansible is my user of my environnement ....
>
> Thanks for your help community ansible !! :)

At any rate you can't use the same host name twice in your inventory file.

Regards
Racke

>
> Regards,
>
> Le mercredi 21 août 2019 10:44:47 UTC+2, Mark Anthony Garcia a écrit :
>
> For me I use the local users from the ansible controllers by calling the "{{ lookup('env','USER') }}".
>
> On Tuesday, August 20, 2019 at 5:00:33 PM UTC+2, Karther wrote:
>
> Hey,
>
> I want to know if possible use a lot of user for ansible.
>
> Exemple, if i use *ansible_user=user1, user2*
>
> because i want to use *serial: 1* 
>
> And i want that ansible use firt user1 and secondaly user2
>
> If possible or not please ??
>
> Regards,
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/cfedbf4f-adc1-4b50-82a8-8c12233549f4%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/cfedbf4f-adc1-4b50-82a8-8c12233549f4%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Karther

unread,
Aug 21, 2019, 8:14:58 AM8/21/19
to Ansible Project
Hey all !!

Ok thanks very much community ansible for your help !! :)

It's very pity that ansible not can play the same playbook on the same host with different user ...

Thanks very much for your help !! :)

Regards,

Karther


Le mardi 20 août 2019 17:00:33 UTC+2, Karther a écrit :
Hey,

I want to know if possible use a lot of user for ansible.

Exemple, if i use ansible_user=user1, user2

because i want to use serial: 1 

Stephen Maher

unread,
Aug 21, 2019, 8:45:08 AM8/21/19
to ansible...@googlegroups.com
Hi 

Is this what you are looking for?? 

---

- hosts: localhost

  gather_facts: no

  

  tasks:

    - name: Run a command as stephen.maher

      command: whoami

      become: yes

      become_method: sudo

      become_user: stephen.maher

      register: output


    - debug:

        var: output.stdout_lines

    

    - name: Run a command as root

      command: whoami

      become: yes

      become_method: sudo

      become_user: root

      register: output


    - debug:

        var: output.stdout_lines



$ ansible-playbook  test.yml

 


PLAY [localhost] ***********************************************************************************************************************************************************************************************


TASK [Run a command as stephen.maher] **************************************************************************************************************************************************************************

changed: [localhost]


TASK [debug] ***************************************************************************************************************************************************************************************************

ok: [localhost] => {

    "output.stdout_lines": [

        "stephen.maher"

    ]

}


TASK [Run a command as nobody] *********************************************************************************************************************************************************************************

changed: [localhost]


TASK [debug] ***************************************************************************************************************************************************************************************************

ok: [localhost] => {

    "output.stdout_lines": [

        "root"

    ]

}


PLAY RECAP *****************************************************************************************************************************************************************************************************

localhost                  : ok=4    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   




--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1aeb59b1-aff3-44a6-b530-b2284013169e%40googlegroups.com.


--

Regards,


Stephen Maher

stephe...@ocado.com | 0777 5832553

UNIX Engineer

Ocado Technology, Buildings One & Two, Trident Place, Mosquito Way, Hatfield, Hertfordshire, 

AL10 9UL


ocado.com


Need some work done by any of the Infrastructure Teams? Click here! 



Notice:
This email is confidential and may contain copyright material of members of the Ocado Group. Opinions and views expressed in this message may not necessarily reflect the opinions and views of the members of the Ocado Group.

If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses.

References to the "Ocado Group" are to Ocado Group plc (registered in England and Wales with number 7098618) and its subsidiary undertakings (as that expression is defined in the Companies Act 2006) from time to time. The registered office of Ocado Group plc is Buildings One & Two, Trident Place, Mosquito Way, Hatfield, Hertfordshire, AL10 9UL.

Stefan Hornburg (Racke)

unread,
Aug 21, 2019, 8:57:44 AM8/21/19
to ansible...@googlegroups.com
On 8/21/19 2:14 PM, Karther wrote:
> Hey all !!
>
> Ok thanks very much community ansible for your help !! :)
>
> It's very pity that ansible not can play the same playbook on the same host with different user ...
>
> Thanks very much for your help !! :)
>
> Regards,
>
> Karther

I didn't say that, but in the inventory you can't use the hostname twice. You can cheat with
two different "fake" host names and ip address in the inventory line, but a better solution
would be to loop the tasks over the users. For example you can use a custom variable containing
both user names and loop over them in the tasks.

Regards
Racke

>
> Le mardi 20 août 2019 17:00:33 UTC+2, Karther a écrit :
>
> Hey,
>
> I want to know if possible use a lot of user for ansible.
>
> Exemple, if i use *ansible_user=user1, user2*
>
> because i want to use *serial: 1* 
>
> And i want that ansible use firt user1 and secondaly user2
>
> If possible or not please ??
>
> Regards,
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/1aeb59b1-aff3-44a6-b530-b2284013169e%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Karther

unread,
Aug 21, 2019, 11:38:17 AM8/21/19
to Ansible Project
Hey,

How do that please ???

I am amateur for ansible 

Thanks,

Regards,
Reply all
Reply to author
Forward
0 new messages