Hello Alicia,

I just ran ad-hoc command with -u ansible parameter like below:

$ ansible all -i production  -u ansible -l mygroup -a "uptime"
myserver | CHANGED | rc=0 >>
 12:13:22 up 11 days,  2:26,  2 users,  load average: 0.00, 0.02, 0.05

ansible user is defined on myserver, and it is in sudoers file in wheel 
group without password required.

On Friday, December 6, 2019 at 12:10:05 PM UTC-5, alicia wrote:
>
> I don’t think the failure is related to using or not using “sudo”. The 
> playbook failed because Ansible could not connect to the remote machine. 
>
> The error message:
>
> fatal: [myserver]: UNREACHABLE! => {"changed": false, "msg": "*Failed to 
> connect to the host via ssh*: 
> ============================================================\n|Permission 
> denied (publickey,password,keyboard-
> interactive).", "unreachable": true}
>
> tells you that Ansible cannot connect to ‘myserver’ over SSH. If you try 
> to connect to the target machine using SSH and the user ‘ansible’ from the 
> command line, does that work? Do you have to type in a password? If you’re 
> using SSH keys, does the ‘ansible’ user have permission to access the 
> correct key?
>
> See 
> https://docs.ansible.com/ansible/latest/user_guide/connection_details.html#ssh-key-setup
>  for 
> information on setting up SSH keys. 
>
> Hope this helps point you in the right direction.
>
> Alicia
>
> On Dec 6, 2019, at 10:44 AM, Xinhuan Zheng <[email protected] 
> <javascript:>> wrote:
>
> Hello,
>
>
>> It's not necessary to use the "vars:" directive in the files. 
>> See "Organizing host and group variables" 
>>
>> https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#organizing-host-and-group-variables
>>  
>>
>> # group_vars/all 
>> remote_user: ansible 
>> become: yes 
>> become_method: sudo 
>>
>> Cheers, 
>>
>>         -vlado 
>>
>
> I changed per advice.  Here is my changed file:
>
> ---
> # group_vars/all
>
> remote_user: ansible
> become: yes
> become_method: sudo
>
> However, this doesn't work either. I got same Permission Denied error like 
> my previous run
>
> - Xinhuan Zheng
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/ansible-project/c0f93f0f-315a-47f5-a645-17a35bd7ae82%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/ansible-project/c0f93f0f-315a-47f5-a645-17a35bd7ae82%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/44684370-2c51-468b-9165-feb6ec743eca%40googlegroups.com.

Reply via email to