title: Ansible stat module not working
body: <p>I need some help here:</p>
  
  <p>I am creating virtual machines with Vagrant to configure some cluster on them. For the first VM, which I want to use as an Ansible control node, I'm running Ansible from my local machine to install and configure Ansible in my  Control Node.</p>
  
  <p>The problem appears when I try to check if the <code>.inventory</code> file exists and try to copy the file to the home directory (inside the VM).</p>
  
  <p>The same command that I use for the inventory file works just file to check the stat of the .ansible.cfg file but not for the inventory file. </p>
  
  <p>Do you guys have any idea what I'm doing wrong?</p>
  
  <p><code>roles/ansible/tasks/main.yml</code></p>
  
  <pre><code>---
  - name: install epel-release
    yum:
      name: epel-release
      state: present
  
  - name: install ansible
    yum:
      name: ansible
      state: present
  
  - name: stat ansible configuration file
    stat:
      path: "{{ cfg_file }}"
    register: stat_ansible_config
  
  - name: copy .ansible.cfg to home directory
    copy:
      src: .ansible.cfg
      dest: /home/{{ user }}/.ansible.cfg
      owner: "{{ user }}"
      group: "{{ group }}"
      mode: 0644
    when: stat_ansible_config.stat.exists
  
  - name: stat ansible inventory file
    stat:
      path: "{{ inventory_file }}"
    register: stat_inventory
  
  - name: copy .inventory to home directory
    copy:
      src: .inventory
      dest: /home/{{ user }}/.inventory
      owner: "{{ user }}"
      group: "{{ group }}"
      mode: 0644
    when: stat_inventory.stat.exists
  ...
  </code></pre>
  
  <p><code>roles/ansible/vars/main.yml</code></p>
  
  <pre><code>---
  user: vagrant
  group: vagrant
  cfg_file:       /{{ user }}/provision/playbooks/roles/ansible/files/.ansible.cfg
  inventory_file: /{{ user }}/provision/playbooks/roles/ansible/files/.inventory
  ...
  </code></pre>
  
  <p><code>the playbook:</code></p>
  
  <pre><code>---
  - hosts: controller
    become: yes
  
    roles:
      - ansible
  ...
  </code></pre>
  
  <p><code>and the output:</code></p>
  
  <pre><code>TASK [ansible : stat ansible configuration file] *******************************
  
  ok: [controller] =&gt; {
      "changed": false,
      "invocation": {
          "module_args": {
              "checksum_algorithm": "sha1",
              "follow": false,
              "get_checksum": true,
              "get_md5": true,
              "mime": false,
              "path": "/vagrant/provision/playbooks/roles/ansible/files/.ansible.cfg"
          },
          "module_name": "stat"
      },
      "stat": {
          "atime": 1485527858.0,
          "checksum": "46acc076fda7e38fd7262fbc88f8ab4e1f52ddca",
          "ctime": 1485452789.0,
          "dev": 38,
          "executable": false,
          "exists": true,
          "gid": 1000,
          "gr_name": "vagrant",
          "inode": 118,
          "isblk": false,
          "ischr": false,
          "isdir": false,
          "isfifo": false,
          "isgid": false,
          "islnk": false,
          "isreg": true,
          "issock": false,
          "isuid": false,
          "md5": "0cb8c97246776dc7e88fe44f19c3278f",
          "mode": "0644",
          "mtime": 1485452789.0,
          "nlink": 1,
          "path": "/vagrant/provision/playbooks/roles/ansible/files/.ansible.cfg",
          "pw_name": "vagrant",
          "readable": true,
          "rgrp": true,
          "roth": true,
          "rusr": true,
          "size": 164,
          "uid": 1000,
          "wgrp": false,
          "woth": false,
          "writeable": true,
          "wusr": true,
          "xgrp": false,
          "xoth": false,
          "xusr": false
      }
  }
  
  TASK [ansible : copy .ansible.cfg to home directory] ***************************
  
  ok: [controller] =&gt; {
      "changed": false,
      "checksum": "46acc076fda7e38fd7262fbc88f8ab4e1f52ddca",
      "dest": "/home/vagrant/.ansible.cfg",
      "diff": {
          "after": {
              "path": "/home/vagrant/.ansible.cfg"
          },
          "before": {
              "path": "/home/vagrant/.ansible.cfg"
          }
      },
      "gid": 1000,
      "group": "vagrant",
      "invocation": {
          "module_args": {
              "backup": null,
              "content": null,
              "delimiter": null,
              "dest": "/home/vagrant/.ansible.cfg",
              "diff_peek": null,
              "directory_mode": null,
              "follow": false,
              "force": false,
              "group": "vagrant",
              "mode": 420,
              "original_basename": ".ansible.cfg",
              "owner": "vagrant",
              "path": "/home/vagrant/.ansible.cfg",
              "recurse": false,
              "regexp": null,
              "remote_src": null,
              "selevel": null,
              "serole": null,
              "setype": null,
              "seuser": null,
              "src": ".ansible.cfg",
              "state": null,
              "unsafe_writes": null,
              "validate": null
          }
      },
      "mode": "0644",
      "owner": "vagrant",
      "path": "/home/vagrant/.ansible.cfg",
      "secontext": "unconfined_u:object_r:user_home_t:s0",
      "size": 164,
      "state": "file",
      "uid": 1000
  }
  
  TASK [ansible : stat ansible inventory file] ***********************************
  
  ok: [controller] =&gt; {
      "changed": false,
      "invocation": {
          "module_args": {
              "checksum_algorithm": "sha1",
              "follow": false,
              "get_checksum": true,
              "get_md5": true,
              "mime": false,
              "path": null
          },
          "module_name": "stat"
      },
      "stat": {
          "exists": false
      }
  }
  
  TASK [ansible : copy .inventory to home directory] *****************************
  
  task path: /Users/alessandro/Go/src/github.com/alesr/neo4go/provision/playbooks/roles/ansible/tasks/main.yml:31
  skipping: [controller] =&gt; {
      "changed": false,
      "skip_reason": "Conditional check failed",
      "skipped": true
  }
  </code></pre>