Aim
The aim is to deploy software once the build passed using Ansible and Gitlab.
Problem
ansible-playbook playbook.yml -u root --private-key=key.pem
deploys the software, but
sudo -u gitlab-runner ansible-playbook playbook.yml -u root --private-key=key.pem
results in:
PLAY ***************************************************************************
TASK [setup] *******************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: OSError: [Errno 13] Permission denied: '/root/.ansible'
fatal: [system.example.com]: FAILED! => {"failed": true, "stdout": ""}
NO MORE HOSTS LEFT *************************************************************
PLAY RECAP *********************************************************************
system.example.com : ok=0 changed=0 unreachable=0 failed=1
Discussion
Running
ansible-playbook --help
shows that-u
is the remote_user. As this is set toroot
the issue should not occur.logging in as
gitlab-runner
and subsequently runansible-playbook playbook.yml -u root --private-key=key.pem
succeeds