---
- hosts: 127.0.0.1
connection: local
vars:
repo: FILL THIS IN
tasks:
- name: 'Clear out the existing git _remote_ repo'
file: path="{{ repo }}" state=absent
- name: 'Clear out the local repo'
file: path="localcopy" state=absent
- name: 'create directory for _remote_ repo'
file: path="{{ repo }}" state=directory
- name: 'init _remote_ git repo'
command: "git init"
args:
chdir: "{{ repo }}"
- name: 'create file'
shell: "echo hello >> file"
args:
chdir: "{{ repo }}"
- name: 'stage file in git'
command: "git add file"
args:
chdir: "{{ repo }}"
- name: 'making commit in _remote_ repo'
command: 'git commit -m First'
args:
chdir: "{{ repo }}"
- name: 'cloning git using ansible module to create _local_ repo'
git: repo="file://{{ repo }}"
dest='localcopy'
version="master"
force=yes
- name: 'creating new branch in _remote_ repo'
command: 'git checkout -b old-branch'
args:
chdir: "{{ repo }}"
- name: 'changing file in _remote_ repo'
shell: "echo hello2 >> file"
args:
chdir: "{{ repo }}"
- name: 'making new commit in _remote_ repo'
command: 'git commit -a -m Second'
args:
chdir: "{{ repo }}"
- name: 'switch branches to old-branch in _local_ repo using git ansible module'
git: repo="file://{{ repo }}"
dest='localcopy'
version="old-branch"
force=yes
- name: 'creating new-branch in _remote_ repo'
command: 'git checkout -b new-branch'
args:
chdir: "{{ repo }}"
- name: "running git ls-remote on _local_ to verify branch exists on _remote_"
shell: "git ls-remote | grep new-branch"
args:
chdir: "localcopy"
- name: 'attempting to switch to new-branch in _local_ repo'
git: repo="file://{{ repo }}"
dest='localcopy'
version="new-branch"
force=yes