nwl-ci/playbooks/getting_started/clone-repository.yml

44 lines
1.6 KiB
YAML

- name: Clone a Git Repository
hosts: "{{ target }}"
gather_facts: false
vars:
git_repo_path: "~/nwl-ci"
ssh_auto_sshadd_file: "./auto-sshadd"
ssh_keyfile: "~/.ssh/testvm_ed25519"
ssh_passphrase: !vault |
$ANSIBLE_VAULT;1.1;AES256
61323235356163363166663139613464303262333231656236313335313133373330316431333139
3135643639363966653938663666653831393132633765340a306665393864343466376637386661
39353535616366393631333161613065356666626266396138633866346462316365663339613263
6564643935326565630a386266376230613230336564363066373730363239303763663666363462
35353634626464656436633165316336323839616463333064633363306337353534
tasks:
- name: Check if auto-sshadd file exists
stat:
path: "{{ ssh_auto_sshadd_file }}"
register: auto_sshadd_stat
- name: Prepare auto ssh-add file
ansible.builtin.shell: |
echo '#!/bin/bash' > {{ ssh_auto_sshadd_file }}
echo 'echo $SSH_PASS' >> {{ ssh_auto_sshadd_file }}
chmod +x {{ ssh_auto_sshadd_file }}
no_log: true
when: not auto_sshadd_stat.stat.exists
- name: Clone and Update Repository
ansible.builtin.shell: |
eval `ssh-agent -s`
SSH_PASS={{ssh_passphrase}} DISPLAY=1 SSH_ASKPASS="{{ssh_auto_sshadd_file}}" ssh-add {{ssh_keyfile}} < /dev/null
if [[ ! -d {{git_repo_path}} ]]; then
git clone ssh://git@bitbucket.gad.local:7999/nm-nsp/nwl-ci.git {{git_repo_path}}
fi
cd {{git_repo_path}}
git checkout develop
git fetch -ap
git pull
args:
executable: /bin/bash
no_log: true