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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With