Need help to find how to run root command with non-root user and escalated privilages

Hi,

I highly appreciate if anybody can help, please

############### playbook ##################

  • hosts: dpie_prod
    user: dpiesa
    tasks:
  • name: install telnet
    yum: pkg=telnet state=installed update_cache=true

command: sudo yum install telnet -y

become: yes
become_user: root
become_method: sudo

The above does not work and throws this error

TASK [install telnet] ****************************************************************************************************************************************
[WARNING]: Module invocation had junk after the JSON data: usage: sudo -e [-S] [-p prompt] [-u username|#uid] file …

fatal: [lind01.corp.acxiom.net]: FAILED! => {“changed”: false, “module_stderr”: “Shared connection to lind01.corp.acxiom.net closed.\r\n”, “module_stdout”: “sudo: illegal option `-n’\r\nusage: sudo -h | -K | -k | -L | -l | -V | -v\r\nusage: sudo [-bEHPS] [-p prompt] [-u username|#uid] [VAR=value]\r\n {-i | -s | }\r\nusage: sudo -e [-S] [-p prompt] [-u username|#uid] file …\r\n”, “msg”: “MODULE FAILURE”, “rc”: 1}
to retry, use: --limit @/home/dpiesa/playbooks/install_telnet.retry

You seem to have a non standard/old sudo, change the default
become_flags as they seem to be causing the problem, specifically,
remove -n (default: '-H -S -n'
)

I think if you set ‘become’ then you don’t need to use sudo.
Also, why don’t you use the module to install packages instead of executing yum?
http://docs.ansible.com/ansible/latest/modules/yum_module.html

Example:

  • name: install one specific version of Apache
    yum:
    name: httpd-2.2.29-1.4.amzn1
    state: present

Try:

  • hosts: dpie_prod
    user: dpiesa
    become: True

tasks:

  • name: install telnet
    yum: pkg=telnet state=installed update_cache=true

command: sudo yum install telnet -y

Not sure how can I specifically remove this -n

Below is my code/error/other info if you can help, please

Code : -

Hi Abhay i still have the error

Code : -

Are you able to do sudo without password

Brian, Actually it worked instead of removing -n i added “default: '-H -S” at the end of the file

Thank you very much, I really appreciate it