Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible module failure. "/bin/sh: sudo: command not found" although it is available on machine I am running against

Tags:

sudo

ansible

I have a Gitlab pipeline that uses a gitlab runner to deploy from. From the runner, I run ansible to reach out and configure one of our servers.

In my pipeline step where I run ansible-playbook, I have the following setup:

deploy:
image: registry.com/ansible
stage: deploy
script:
 - ansible-playbook server.yml --inventory=hosts.yml

This reaches out to my host and begins to deploy but hits a snag on the first task that has a "become: yes" statement in it. It fails providing the following error:

TASK [mytask : taskOne] ************
task path: my/file/location/path.yml
fatal: [server01[ : FAILED! => {
  "changed": false,
  "module_stderr": "/bin/sh: sudo: command not found\n",
  "module_stdout": "",
  "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",

I can login to my server (server01) and run sudo without issues. Any thoughts on what could be causing this? Thanks.

like image 333
IT_User Avatar asked Oct 24 '25 14:10

IT_User


1 Answers

My guess is that you are not using the same user in the GitLab pipeline and for your sudo test on the machine. In this case you should try to become this user on the host and try the sudo command to troubleshoot it. It seems to be a matter of PATH not something related to the configuration of the sudoers (that is a common problem).

As a workaround (it will not solve the sudo problem) you could try to use an alternate become_method like su, more detail in the doc.

- name: Run a command with become su
  command: somecommand
  become: yes
  become_method: su
like image 108
Romain Avatar answered Oct 27 '25 19:10

Romain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!