I seem to have a problem where if two branches point to the same commit but
have a different name the ansible git module may fail. I believe the reason
is that when the module sees that the commits are the same between HEAD on
the local repo, and the remote requested branch, it doesn't bother to do a
fetch to update the local branches
Here is a playbook I created that demonstrates the issue, the last step in
the play fails and it isn't clear to me why it should fail.
---
- 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
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/8f472b7e-1562-4842-bd22-7d8a6c1bd220%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.