Difference between revisions of "Git with Ansible"

From Knowledge Center
Jump to: navigation, search
 
Line 60: Line 60:
 
     path: /tmp/deploy/.ssh/deploy_keys
 
     path: /tmp/deploy/.ssh/deploy_keys
 
     state: absent
 
     state: absent
 +
</pre>
 +
 +
Run:
 +
 +
<pre>
 +
$ ansible-playbook -i inventory.ini -u ruan git-run.yml
 
</pre>
 
</pre>
  
Line 70: Line 76:
 
[[Category:All]]
 
[[Category:All]]
 
[[Category:Ansible]]
 
[[Category:Ansible]]
[[Category:Git]]
+
[[Category:Github]]

Latest revision as of 15:21, 21 March 2019

Clone a private github repository with ansible:

$ cat git-run.yml
---
- name: git-test
  hosts: laptop
  vars_files:
    - vars.yml
  roles:
    - git-test
$ cat vars.yml
git_repo: git@github.com:user/reponame.git
deploy_private_key: /Users/ruan/workspace/repo/ansible/deploy_keys
cat roles/git-test/tasks/main.yml
- name: ensure directory has correct permissions.
  file:
    path: /tmp/deploy
    state: directory
    owner: ruan
    group: staff

- name: ensure .ssh directory exists.
  file:
    path: /tmp/deploy/.ssh
    state: directory
    mode: 0700
    owner: ruan
    group: staff

- name: places keys in path
  copy:
    src: "{{ deploy_private_key }}"
    dest: /tmp/deploy/.ssh/deploy_keys
    mode: 0600
    owner: ruan
    group: staff

# See: https://stackoverflow.com/a/37096534/100134
#- name: Ensure setfacl support is present.
#  package: name=acl

- name: clone to path.
  git:
    repo: "{{ git_repo }}"
    dest: /tmp/deploy/main-repo
    accept_hostkey: yes
    key_file: /tmp/.ssh/deploy_keys
  become_user: ruan

- name: delete deploy key
  file:
    path: /tmp/deploy/.ssh/deploy_keys
    state: absent

Run:

$ ansible-playbook -i inventory.ini -u ruan git-run.yml

Resources: