1

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

  1. Running ansible-playbook --help shows that -u is the remote_user. As this is set to root the issue should not occur.

  2. logging in as gitlab-runner and subsequently run ansible-playbook playbook.yml -u root --private-key=key.pem succeeds

030
  • 5,901
  • 13
  • 68
  • 110

1 Answers1

1

Cause

Issue was caused because the host was omitted from the known host file that resides in the home directory of the gitlab-runner user

Solution

  1. login as gitlab-runner, i.e. sudo su - gitlab-runner
  2. run playbook, i.e. ansible-playbook playbook.yml -u root --private-key=key.pem
  3. enter yes if Are you sure you want to continue connecting (yes/no)? appears
  4. click the retry button in gitlab to restart the build
030
  • 5,901
  • 13
  • 68
  • 110