Issue 1:
From @8191 on 2016-09-13T18:12:42Z

ISSUE TYPE

Bug Report

COMPONENT NAME

git

ANSIBLE VERSION

ansible 2.2.0

(current devel branch)

CONFIGURATION

OS / ENVIRONMENT

Host: CentOS 7, Target: CentOS 7

SUMMARY

If a submodule's checked out commit is different than the SHA-1 commited to the super-repository, an update attempt of the super-repository using the git module always fails with Local modifications exist, even if force=yes was given.

STEPS TO REPRODUCE

Preconditions

Repo repo.git, which contains submodules, has already been cloned

At least one submodule has been checked out at a different commit than commited to the repo repo.git; i.e. the instance of the checked out repo is "dirty" and git status shows something like:

# On branch master
# Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
# (use "git pull" to update your local branch)
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: <submodule> (new commits)

Example playbook to reproduce

- hosts: all
gather_facts: False
tasks:
- name: checkout repo
git:
repo: user@host:/var/lib/git/repo.git
dest: /tmp/repo.git
accept_hostkey: yes
ssh_opts: "-o StrictHostKeyChecking=no"
force: yes
update: yes

EXPECTED RESULTS

The super-repository should be updated and submodules shall be checkedout to the stored SHA-1 reference within the super-repository.

ACTUAL RESULTS

fatal: [cali]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "git"
},
"module_stderr": "OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /home/mf/.ssh/config\r\ndebug1: /home/mf/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 25086\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to cali closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_rYIDTj/ansible_module_git.py\", line 1022, in <module>\r\n main()\r\n File \"/tmp/ansible_rYIDTj/ansible_module_git.py\", line 973, in main\r\n result.update(changed=True, after=remote_head, msg='Local modifications exist')\r\nUnboundLocalError: local variable 'remote_head' referenced before assignment\r\n",
"msg": "MODULE FAILURE"
}

Copied from original issue: ansible/ansible-modules-core#4817

Issue 2:
From @8191 on 2016-09-13T18:12:42Z

ISSUE TYPE

Bug Report

COMPONENT NAME

git

ANSIBLE VERSION

ansible 2.2.0

(current devel branch)

CONFIGURATION

OS / ENVIRONMENT

Host: CentOS 7, Target: CentOS 7

SUMMARY

If a submodule's checked out commit is different than the SHA-1 commited to the super-repository, an update attempt of the super-repository using the git module always fails with Local modifications exist, even if force=yes was given.

STEPS TO REPRODUCE

Preconditions

Repo repo.git, which contains submodules, has already been cloned

At least one submodule has been checked out at a different commit than commited to the repo repo.git; i.e. the instance of the checked out repo is "dirty" and git status shows something like:

# On branch master
# Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
# (use "git pull" to update your local branch)
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: <submodule> (new commits)

Example playbook to reproduce

- hosts: all
gather_facts: False
tasks:
- name: checkout repo
git:
repo: user@host:/var/lib/git/repo.git
dest: /tmp/repo.git
accept_hostkey: yes
ssh_opts: "-o StrictHostKeyChecking=no"
force: yes
update: yes

EXPECTED RESULTS

The super-repository should be updated and submodules shall be checkedout to the stored SHA-1 reference within the super-repository.

ACTUAL RESULTS

fatal: [cali]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "git"
},
"module_stderr": "OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /home/mf/.ssh/config\r\ndebug1: /home/mf/.ssh/config line 1: Applying options for *\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 25086\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to cali closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_rYIDTj/ansible_module_git.py\", line 1022, in <module>\r\n main()\r\n File \"/tmp/ansible_rYIDTj/ansible_module_git.py\", line 973, in main\r\n result.update(changed=True, after=remote_head, msg='Local modifications exist')\r\nUnboundLocalError: local variable 'remote_head' referenced before assignment\r\n",
"msg": "MODULE FAILURE"
}

Copied from original issue: ansible/ansible-modules-core#4817