0

How could I create a list for all possible commands an ansible-playbook is using so that I could create a sudoers file?

For testing the playbooks, temporally I create an entry in the /etc/sudoers.d:

tempuser ALL=(ALL:ALL) NOPASSWD:ALL

But is there a plugin or way to get like the list of commands so that I could later create a list like

tempuser ALL= NOPASSWD:  /bin/systemctl start  mariadb.service
...

Any ideas?

nbari
  • 25,603
  • 10
  • 76
  • 131
  • See [Ansible sudo with restrictive permission's](https://stackoverflow.com/questions/60365112/ansible-sudo-with-restrictive-permissions). – Vladimir Botka Feb 04 '21 at 14:19

1 Answers1

1

If you intend to use privilege escalation with ansible then privilege escalation must be general

You cannot limit privilege escalation permissions to certain commands. Ansible does not always use a specific command to do something but runs modules (code) from a temporary file name which changes every time. If you have ‘/sbin/service’ or ‘/bin/chmod’ as the allowed commands this will fail with ansible as those paths won’t match with the temporary file that Ansible creates to run the module. If you have security rules that constrain your sudo/pbrun/doas environment to running specific command paths only, use Ansible from a special account that does not have this constraint, or use Red Hat Ansible Tower to manage indirect access to SSH credentials.

As demonstrated in the above documentation quote, this is a well known limitation of the tool. If this is a problem in your environment, either look at the above proposed workarounds in documentation quote, or don't use ansible at all.

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
  • could you please share the possible workarounds? – nbari Feb 04 '21 at 14:11
  • `If you have security rules that constrain your sudo/pbrun/doas environment to running specific command paths only, use Ansible from a special account that does not have this constraint, or use Red Hat Ansible Tower to manage indirect access to SSH credentials.` ... or don't use ansible at all. – Zeitounator Feb 04 '21 at 14:21