Thanks,

 

I think that is sort of what my colleague was alluding to – slightly more 
elegant though.

 

So, it will run include-3.yml 3 times?  And one will succeed? I obviously have 
a number of tasks to run after this…

 

I was kind of hoping to keep this logic all in one with the idea that I might 
create a single report after about what user worked and what was done … ( not 
to say that couldn’t be done this way as well, but just my method of thinking)

 

Also it seem strange that assigning variable to remote_user seems to only work 
once – is that correct?

 

I actually dug down into the source and the ssh.py  connection plugin and it 
didn’t look as though it would be a big deal to pass a list to it but I don’t 
particularly want to wind up with my ‘own’ version of ansible plugins so unless 
someone thought it was worthwhile having then I probably won’t.

 

Saying that, as AWS instances do have different user accounts according to 
flavor, and you can’t get the flavor without connecting, it seems like it  
might be useful?

 

Regards

Bill

 

 

 

 

From: ansible-project@googlegroups.com <ansible-project@googlegroups.com> On 
Behalf Of Dan Linder
Sent: Monday, July 8, 2019 11:21 AM
To: Ansible Project <ansible-project@googlegroups.com>
Subject: Re: [ansible-project] using different remote_user until success

 

Are you opposed to using a second playbook and using the "include:" module like 
this?


---
- hosts: all
  gather_facts: false
  tasks:
  - name: try users
    #remote_user: "{{ item }}"
    include: include-3.yml
    vars:
      my_remote_user: "{{ item }}"
    with_items:
      - centos
      - root
      - ec2-user

 

Then the "include-3.yml" file looks like this:

---
- name: try users
  remote_user: "{{ my_remote_user }}"
  ping:
  ignore_unreachable: true
  failed_when: false

 

This then tries to connect with each user:

<localhost> ESTABLISH SSH CONNECTION FOR USER: centos
<localhost> ESTABLISH SSH CONNECTION FOR USER: root
<localhost> ESTABLISH SSH CONNECTION FOR USER: ec2-user


On Monday, July 8, 2019 at 11:16:47 AM UTC-5, william...@gmail.com 
<mailto:william...@gmail.com>  wrote:

Sorry, pressed send inadvertently there... 

-----Original Message----- 
From: william...@gmail.com <javascript:>  <william...@gmail.com <javascript:> > 
Sent: Monday, July 8, 2019 10:09 AM 
To: ansible...@googlegroups.com <javascript:>  
Subject: RE: [ansible-project] using different remote_user until success 

Hi Brian, this seemed like a good way to do it, but I haven't been able to make 
it work - I haven't done much logic in my plays... mostly just point and shoot 
tasks. 

--- 
- hosts: test 
  gather_facts: false 
  tasks: 
  - name: try users 
    remote_user: "{{ item }}" 
    ping: 
    ignore_unreachable: true 
    failed_when: false 
    with_items: 
      - centos 
      - root 
      - ec2-user 

When I run this, it loops 3 times, and at the start of each I get... 

<xxx.xxx.xxx.xxx> ESTABLISH SSH CONNECTION FOR USER: centos 

failed: [xxx.xxx.xxx.xxx] (item=centos) => { 
    "ansible_loop_var": "item", 
    "item": "centos", 

< xxx.xxx.xxx.xxx > ESTABLISH SSH CONNECTION FOR USER: centos 

failed: [xxx.xxx.xxx.xxx] (item=root) => { 
    "ansible_loop_var": "item", 
    "item": "root", 
    "msg": "Failed to connect to the host via ssh: Permission denied 
(publickey,password).", 
    "unreachable": true 
< xxx.xxx.xxx.xxx > ESTABLISH SSH CONNECTION FOR USER: centos 
failed: [xxx.xxx.xxx.xxx] (item=ec2-user) => { 
    "ansible_loop_var": "item", 
    "item": "ec2-user", 
    "msg": "Failed to connect to the host via ssh: Permission denied 
(publickey,password).", 
    "unreachable": true 
} 

So the item is changing, but it seems that you can only set remote_user once? 

I assume remote_user is what I should be using in the playbook?  Ansible_user 
in the config file and remote_user in the playbook right? 

This seems like great solution if I could get it to work. 

Any advice would be hugely appreciated at this point. 

Regards 
Bill 


-----Original Message----- 
From: ansible...@googlegroups.com <javascript:>  <ansible...@googlegroups.com 
<javascript:> > On Behalf Of Brian Coca 
Sent: Friday, July 5, 2019 8:10 AM 
To: Ansible Project <ansible...@googlegroups.com <javascript:> > 
Subject: Re: [ansible-project] using different remote_user until success 

loop a ping task over the users and use 'ignore_unreachable' and 
failed_when: false to keep running that task, register the result and set 
ansible_user using the results. 


-- 
---------- 
Brian Coca 

-- 
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...@googlegroups.com <javascript:> . 
To post to this group, send email to ansible...@googlegroups.com <javascript:> 
. 
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7ewm22AQ7h9vG7qkfRL37-Zy8w7izdEGqQCD6trNrfKSw%40mail.gmail.com.
 
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 ansible-project+unsubscr...@googlegroups.com 
<mailto:ansible-project+unsubscr...@googlegroups.com> .
To post to this group, send email to ansible-project@googlegroups.com 
<mailto:ansible-project@googlegroups.com> .
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3a43d047-2da0-479f-b7e5-b3e1f286476a%40googlegroups.com
 
<https://groups.google.com/d/msgid/ansible-project/3a43d047-2da0-479f-b7e5-b3e1f286476a%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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/048d01d535c5%241c11dda0%24543598e0%24%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to