I have the following Gitlab-ci.yml config that calls an Ansible provisioning script:
image: ubuntu
deploy to dev:
stage: deploy
only:
- develop
environment:
name: dev
url: http://URL HERE/
script:
# Install required packages
- apt-get update && apt-get install -y software-properties-common
- apt-add-repository ppa:ansible/ansible
- apt-get update && apt-get install -y ansible openssh-client rsync
# Set up our SSH key
- eval $(ssh-agent -s)
- ssh-add <(echo "$MY_SSH_KEY")
- mkdir -p ~/.ssh; chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# Deploy via ansible
- ansible-galaxy install -r ansible/requirements.yml --roles-path=ansible/roles
- ansible-playbook -i ansible/dev ansible/deploy.yml
This will execute the ansible-playbook and runs the deploy.yml
However; when pipeline is executed the code push fails with the following error:
TASK [Upload the project code] *************************************************
fatal: [URL HERE]: FAILED! => {“msg”: “failed to transfer file to ~ubuntu/.ansible/tmp/ansible-tmp-1526928263.0-14912160974412/synchronize.py: [Errno 2] No such file or directory: ‘~ubuntu/.ansible/tmp/ansible-tmp-1526928263.0-14912160974412/synchronize.py’”}
Deploy.yml:
-
hosts: all
vars_files:
- vars.yml
tasks:
-
name: Ensure project directory exists and is writeable
file:
path: “{{ project_dir }}”
state: directory
owner: “{{ project_user }}”
group: www-data
mode: 0755
become: yes -
name: Upload the project code
synchronize:
src: “…/…/”
dest: “{{ project_dir }}”
recursive: yes
become: yes #tried this with and without -
name: Install composer dependencies
composer: command=install working_dir={{ project_dir }} -
name: Migrate the database
command: php artisan migrate chdir={{ project_dir }}
However; this runs successfully when pulled down and ran manually, additionally, this code executes within the pipeline if Ansible Copy command is used instead of Synchronize, but the Copy command takes 20min to complete. Any ideas / work arounds? I’ve tried setting remote / local paths in my ansible configs and giving different paths for tmp dir but nothing seems to work