2
votes

I have a lab setup with ansible controller + node and exploring few areas.

I am so far setup an user account named ansible in both machines and enabled ssh keybased authentication

Also setup sudo premissions for the user in both machines

When I try to run the below playbook , It works on the local machine and fails on the other node.

--- #Install Telnet - hosts: all name: Install Telnet become: true become_user: ansible become_method: sudo tasks: - yum: name: telnet state: latest

Output is as follows `[ansible@host1 playbooks]$ ansible-playbook telnetDeployYUM.yml

PLAY [Install Telnet] ***********************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************** ok: [192.168.64.6] ok: [192.168.64.5]

TASK [yum] ********************************************************************************************************************************************************************************** ok: [192.168.64.5] fatal: [192.168.64.6]: FAILED! => {"changed": true, "msg": "You need to be root to perform this command.\n", "obsoletes": {"grub2": {"dist": "x86_64", "repo": "@anaconda", "version": "1:2.02-0.64.el7.centos"}, "grub2-tools": {"dist": "x86_64", "repo": "@anaconda", "version": "1:2.02-0.64.el7.centos"}}, "rc": 1, "results": ["Loaded plugins: fastestmirror\n"]} to retry, use: --limit @/home/ansible/playbooks/telnetDeployYUM.retry

PLAY RECAP ********************************************************************************************************************************************************************************** 192.168.64.5 : ok=2 changed=0 unreachable=0 failed=0 192.168.64.6 : ok=1 changed=0 unreachable=0 failed=1

[ansible@host1 playbooks]$ `

I could also manually able to run sudo yum on the failed target as ansible user

I believe sudo set up in correct

[ansible@host2 root]$ sudo whoami root

Can experts share some insights on what I am missing with respect to my failed machine , Thanks.

2

2 Answers

1
votes

Below should work fine

- hosts: all
  name: Install Telnet
  become: yes
  tasks:
    - yum:
      name: telnet
      state: latest

ansible or user through which ansible is getting executed should be in sudoers file.

You are changing your user to ansible which is not required.

1
votes

Run with -vvvv to see what ansible is doing.

Have you setup ansible in sudoers for password less privilege elevation? you are getting a message that it is waiting for "escalation prompt". That means when you are running with become, you are failing to become since it needs the password. Make sure your test user is in /etc/sudoers AND you have it marked for that user to NOT need to enter a password when running sudo commands. The entry should end with :NOPASSWD on the line in that file.