<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/8191/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/8191">@8191</a> on 2016-09-13T18:12:42Z</p>

<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">git</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0"><pre class="notranslate"><code class="notranslate">ansible 2.2.0
</code></pre></div>
<p dir="auto">(current <code class="notranslate">devel</code> branch)</p>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Host: CentOS 7, Target: CentOS 7</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">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 <code class="notranslate">Local modifications exist</code>, even if <code class="notranslate">force=yes</code> was given.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<h6 dir="auto">Preconditions</h6>
<ul dir="auto">
<li>Repo <code class="notranslate">repo.git</code>, which contains submodules, has already been cloned</li>
<li>At least one submodule has been checked out at a different commit than commited to the repo <code class="notranslate">repo.git</code>; i.e. the instance of the checked out repo is "dirty" and <code class="notranslate">git status</code> shows something like:</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# On branch master
# Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
#   (use &quot;git pull&quot; to update your local branch)
#
# Changes not staged for commit:
#   (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
#   (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)
#
#       modified:   &lt;submodule&gt; (new commits)"><pre class="notranslate"><code class="notranslate"># 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 &lt;file&gt;..." to update what will be committed)
#   (use "git checkout -- &lt;file&gt;..." to discard changes in working directory)
#
#       modified:   &lt;submodule&gt; (new commits)
</code></pre></div>
<h6 dir="auto">Example playbook to reproduce</h6>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- 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: &quot;-o StrictHostKeyChecking=no&quot;
        force: yes
        update: yes"><pre class="notranslate"><code class="notranslate">- 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
</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">The super-repository should be updated and submodules shall be checkedout to the stored SHA-1 reference within the super-repository.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [cali]: FAILED! =&gt; {
    &quot;changed&quot;: false, 
    &quot;failed&quot;: true, 
    &quot;invocation&quot;: {
        &quot;module_name&quot;: &quot;git&quot;
    }, 
    &quot;module_stderr&quot;: &quot;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&quot;, 
    &quot;module_stdout&quot;: &quot;Traceback (most recent call last):\r\n  File \&quot;/tmp/ansible_rYIDTj/ansible_module_git.py\&quot;, line 1022, in &lt;module&gt;\r\n    main()\r\n  File \&quot;/tmp/ansible_rYIDTj/ansible_module_git.py\&quot;, 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&quot;, 
    &quot;msg&quot;: &quot;MODULE FAILURE&quot;
}"><pre class="notranslate"><code class="notranslate">fatal: [cali]: FAILED! =&gt; {
    "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 &lt;module&gt;\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"
}
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="176711177" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/4817" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/4817/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/4817">ansible/ansible-modules-core#4817</a></p>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/8191/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/8191">@8191</a> on 2016-09-13T18:12:42Z</p>

<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">git</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0"><pre class="notranslate"><code class="notranslate">ansible 2.2.0
</code></pre></div>
<p dir="auto">(current <code class="notranslate">devel</code> branch)</p>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Host: CentOS 7, Target: CentOS 7</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">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 <code class="notranslate">Local modifications exist</code>, even if <code class="notranslate">force=yes</code> was given.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<h6 dir="auto">Preconditions</h6>
<ul dir="auto">
<li>Repo <code class="notranslate">repo.git</code>, which contains submodules, has already been cloned</li>
<li>At least one submodule has been checked out at a different commit than commited to the repo <code class="notranslate">repo.git</code>; i.e. the instance of the checked out repo is "dirty" and <code class="notranslate">git status</code> shows something like:</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# On branch master
# Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
#   (use &quot;git pull&quot; to update your local branch)
#
# Changes not staged for commit:
#   (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
#   (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)
#
#       modified:   &lt;submodule&gt; (new commits)"><pre class="notranslate"><code class="notranslate"># 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 &lt;file&gt;..." to update what will be committed)
#   (use "git checkout -- &lt;file&gt;..." to discard changes in working directory)
#
#       modified:   &lt;submodule&gt; (new commits)
</code></pre></div>
<h6 dir="auto">Example playbook to reproduce</h6>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- 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: &quot;-o StrictHostKeyChecking=no&quot;
        force: yes
        update: yes"><pre class="notranslate"><code class="notranslate">- 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
</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">The super-repository should be updated and submodules shall be checkedout to the stored SHA-1 reference within the super-repository.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [cali]: FAILED! =&gt; {
    &quot;changed&quot;: false, 
    &quot;failed&quot;: true, 
    &quot;invocation&quot;: {
        &quot;module_name&quot;: &quot;git&quot;
    }, 
    &quot;module_stderr&quot;: &quot;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&quot;, 
    &quot;module_stdout&quot;: &quot;Traceback (most recent call last):\r\n  File \&quot;/tmp/ansible_rYIDTj/ansible_module_git.py\&quot;, line 1022, in &lt;module&gt;\r\n    main()\r\n  File \&quot;/tmp/ansible_rYIDTj/ansible_module_git.py\&quot;, 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&quot;, 
    &quot;msg&quot;: &quot;MODULE FAILURE&quot;
}"><pre class="notranslate"><code class="notranslate">fatal: [cali]: FAILED! =&gt; {
    "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 &lt;module&gt;\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"
}
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="176711177" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/4817" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/4817/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/4817">ansible/ansible-modules-core#4817</a></p>