Issue
I was following this doc to install shiny package in RedHat 7.3. The command provided in the doc is:
$ sudo su - \
-c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""
In Ansible, I wrote it like this:
- name: Installing Shiny Packages
shell: sudo su - -c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""
#when: install_R|changed
I am getting a warning when I run my playbook:
TASK [Installing Shiny Packages] ***********************************************
[WARNING]: Consider using 'become', 'become_method', and 'become_user' rather
than running sudo
changed: [test]
Please let me know how to write this in ansible so that I can avoid the warning.
Solution
It is probably because of the outdated sudo usage from version 1.9. From the official Ansible documentation.
Before
1.9Ansible mostly allowed the use ofsudoand a limited use ofsuto allow a login/remote user to become a different user and execute tasks, create resources with the 2nd user’s permissions. As of1.9,becomesupersedes the oldsudo/su, while still being backwards compatible.
You can remove it by using the become module which allows you to 'become' another user, different from the user that logged into the machine (remote user). You need to set to true to activate privilege escalation.
name: Installing Shiny Packages
shell: R -e "install.packages('shiny', repos='https://cran.rstudio.com/')"
become: true
Answered By - Inian