Repository: ansible/ansible

Issue:
Added three new nameserver facts to the setup module
# Added Three New Nameserver Facts to the Setup Module
-  all_nameservers: A list of IP addresses of all configured name servers.
-  default_nameserver: The first IP address in all_nameservers.
-  resolv_domain: The value of the 'domain' entry used for searching non-dot terminated domains.

All data are taken from /etc/resolv.conf using http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.files%2Fdoc%2Faixfiles%2Fresolv.conf.htm as a file format reference.
## Rationale For This Change
1. `resolv.conf` is common across systems and has a well defined format, so these changes are likely to result in useful facts on most systems.
2. It is certainly _possible_ to list resolvers in vars files related to each host. As the resolvers are facts about the host, it seems to make more sense to provide this information as setup facts.
## Example Real World Usage

Several nginx modules (including `proxy` and `ocsp_staple`) require a DNS name server specified in the nginx configuration files. Providing these facts allows straightforward creation of compatible configuration files using only the template action.



Discussion:
I'm not sure we want to further bloat the setup module for this specific purpose just yet

And we definitely don't need to execute cat to open files.

Previously this has been proposed that someone write something like a nameserver_facts module and keep this optional.

I'm open to listening to reason on why this should be a part of the main setup module rather than something that should be called explicitly, but I really don't understand the part about executing cat.

@mpdehaan Acknowledged. I applied and shipped the wrong patch file.

See pull request #5508 for the correct version of this patch.


Resolving patch:
diff --git a/lib/ansible/modules/source_control/git.py b/lib/ansible/modules/source_control/git.py
--- a/lib/ansible/modules/source_control/git.py
+++ b/lib/ansible/modules/source_control/git.py
@@ -888,7 +888,7 @@ def main():
     ssh_opts  = module.params['ssh_opts']
     umask  = module.params['umask']
 
-    result = dict( warnings=list() )
+    result = dict(changed = False, warnings=list())
 
     # evaluate and set the umask before doing anything else
     if umask is not None:
@@ -968,7 +968,7 @@ def main():
         # this does no checking that the repo is the actual repo
         # requested.
         result['before'] = get_version(module, git_path, dest)
-        result.update(changed=False, after=result['before'])
+        result.update(after=result['before'])
         module.exit_json(**result)
     else:
         # else do a pull
@@ -981,6 +981,7 @@ def main():
             # if force and in non-check mode, do a reset
             if not module.check_mode:
                 reset(git_path, module, dest)
+                result.update(changed=True, msg='Local modifications exist.')
 
         # exit if already at desired sha version
         if module.check_mode:
@@ -990,27 +991,20 @@ def main():
             remote_url_changed = set_remote_url(git_path, module, repo, dest, remote)
         result.update(remote_url_changed=remote_url_changed)
 
-        if need_fetch:
-            if module.check_mode:
-                remote_head = get_remote_head(git_path, module, dest, version, remote, bare)
-                result.update(changed=(result['before'] != remote_head), after=remote_head)
-                # FIXME: This diff should fail since the new remote_head is not fetched yet?!
-                if module._diff:
-                    diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after'])
-                    if diff:
-                        result['diff'] = diff
-                module.exit_json(**result)
-            else:
-                fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec, git_version_used)
+        if module.check_mode:
+            remote_head = get_remote_head(git_path, module, dest, version, remote, bare)
+            result.update(changed=(result['before'] != remote_head), after=remote_head)
+            # FIXME: This diff should fail since the new remote_head is not fetched yet?!
+            if module._diff:
+                diff = get_diff(module, git_path, dest, repo, remote, depth, bare, result['before'], result['after'])
+                if diff:
+                    result['diff'] = diff
+            module.exit_json(**result)
+        else:
+            fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec, git_version_used)
 
         result['after'] = get_version(module, git_path, dest)
 
-        if result['before'] == result['after']:
-            if local_mods:
-                result.update(changed=True, after=remote_head, msg='Local modifications exist')
-                # no diff, since the repo didn't change
-                module.exit_json(**result)
-
     # switch to version specified regardless of whether
     # we got new revisions from the repository
     if not bare:
@@ -1033,7 +1027,6 @@ def main():
     # determine if we changed anything
     result['after'] = get_version(module, git_path, dest)
 
-    result.update(changed=False)
     if result['before'] != result['after'] or local_mods or submodules_updated or remote_url_changed:
         result.update(changed=True)
         if module._diff:


Test patch:
diff --git a/test/integration/targets/git/tasks/main.yml b/test/integration/targets/git/tasks/main.yml
--- a/test/integration/targets/git/tasks/main.yml
+++ b/test/integration/targets/git/tasks/main.yml
@@ -447,7 +447,7 @@
 - name: clear checkout_dir
   file: state=absent path={{ checkout_dir }}
 
-- name: Clone example git repo that we're going to modify
+- name: "Clone example git repo that we're going to modify"
   git:
     repo: '{{ repo_update_url_1 }}'
     dest: '{{ checkout_dir }}/repo'
@@ -652,9 +652,6 @@
   register: git_fetch
   ignore_errors: yes
 
-- name: read file
-  shell: cat {{ checkout_dir }}/a
-
 - name: check update arrived
   assert:
     that:
@@ -718,3 +715,109 @@
     gpg_version.stdout and
     (git_version.stdout | version_compare("2.1.0", '>=') or
     gpg_version.stdout | version_compare("1.4.16", '>='))
+
+- name: clear checkout_dir
+  file: state=absent path={{ checkout_dir }}
+
+# test for https://github.com/ansible/ansible-modules-core/pull/5505
+- name: prepare old git repo
+  shell: rm -rf localmods; mkdir localmods; cd localmods; git init; echo "1" > a; git add a; git commit -m "1"
+  args:
+    chdir: "{{repo_dir}}"
+
+- name: checkout old repo
+  git:
+    repo: '{{ repo_dir }}/localmods'
+    dest: '{{ checkout_dir }}'
+
+- name: "update repo"
+  shell: echo "2" > a; git commit -a -m "2"
+  args:
+    chdir: "{{repo_dir}}/localmods"
+
+- name: "add local mods"
+  shell: echo "3" > a
+  args:
+    chdir: "{{ checkout_dir }}"
+
+- name: fetch with local mods without force (should fail)
+  git:
+    repo: '{{ repo_dir }}/localmods'
+    dest: '{{ checkout_dir }}'
+  register: git_fetch
+  ignore_errors: yes
+
+- name: check fetch with localmods failed
+  assert:
+    that:
+      - git_fetch|failed
+
+- name: fetch with local mods with force
+  git:
+    repo: '{{ repo_dir }}/localmods'
+    dest: '{{ checkout_dir }}'
+    force: True
+  register: git_fetch_force
+  ignore_errors: yes
+
+- name: check update arrived
+  assert:
+    that:
+      - "{{ lookup('file', checkout_dir+'/a' )}} == 2"
+      - git_fetch_force|changed
+
+- name: clear checkout_dir
+  file: state=absent path={{ checkout_dir }}
+
+# localmods and shallow clone
+- name: prepare old git repo
+  shell: rm -rf localmods; mkdir localmods; cd localmods; git init; echo "1" > a; git add a; git commit -m "1"
+  args:
+    chdir: "{{repo_dir}}"
+
+- name: checkout old repo
+  git:
+    repo: '{{ repo_dir }}/localmods'
+    dest: '{{ checkout_dir }}'
+    depth: 1
+
+- name: "update repo"
+  shell: echo "2" > a; git commit -a -m "2"
+  args:
+    chdir: "{{repo_dir}}/localmods"
+
+- name: "add local mods"
+  shell: echo "3" > a
+  args:
+    chdir: "{{ checkout_dir }}"
+
+- name: fetch with local mods without force (should fail)
+  git:
+    repo: '{{ repo_dir }}/localmods'
+    dest: '{{ checkout_dir }}'
+    depth: 1
+  register: git_fetch
+  ignore_errors: yes
+
+- name: check fetch with localmods failed
+  assert:
+    that:
+      - git_fetch|failed
+
+- name: fetch with local mods with force
+  git:
+    repo: '{{ repo_dir }}/localmods'
+    dest: '{{ checkout_dir }}'
+    depth: 1
+    force: True
+  register: git_fetch_force
+  ignore_errors: yes
+
+- name: check update arrived
+  assert:
+    that:
+      - "{{ lookup('file', checkout_dir+'/a' )}} == 2"
+      - git_fetch_force|changed
+
+- name: clear checkout_dir
+  file: state=absent path={{ checkout_dir }}