Answers: <p>According to <a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html" rel="nofollow noreferrer">documentation</a>:</p>
  <blockquote>
  <p>NOTE - For windows clients, the results will be added to a variable
  named after the local file (without extension suffix), rather than ansible_local.</p>
  </blockquote>
  <p>According to your example it should be in <code>ansible_foo</code>, but take into consideration that the files in the path must be PowerShell scripts (with extension .ps1) so maybe <code>foo.fact</code> wasn't actually executed.</p>
  <p>Hope it helps.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-09-28T18:58:19.673Z
Answers: 2020-09-29T06:49:31.270Z
Answers: 2020-09-29T06:49:31.270Z
Answers: mcmx
Body: <p>The ansible_local var is not being populated when using the setup module to gather custom facts on windows.</p>
  <p><strong>Playbook:</strong></p>
  <pre><code>---
  - name: Testing and Debug PB
    hosts: all
    tasks:
    
      - name: Gather Facts
        setup:
          fact_path: 'c:\custom_facts'
  
      - debug:
          msg: &quot;{{ hostvars[inventory_hostname] }}&quot;
  
      - debug:
          msg: &quot;{{ ansible_local }}&quot;
  </code></pre>
  <p><strong>Contents of &quot;C:\custom_facts\foo.fact&quot; on remote host:</strong></p>
  <pre><code>[general]
  asdf=1
  bar=2
  </code></pre>
  <p>Playbook Output:</p>
  <pre><code>ansible-playbook -i inv/dev 301_pb_testing.yml -vv
  ansible-playbook 2.9.12
    config file = /etc/ansible/ansible.cfg
    configured module search path = ['/home/alex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
    executable location = /usr/local/bin/ansible-playbook
    python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
  Using /etc/ansible/ansible.cfg as config file
  
  PLAYBOOK: 301_pb_testing.yml ************************************************************************************************************************************************1 plays in 301_pb_testing.yml
  
  PLAY [Testing and Debug PB] *************************************************************************************************************************************************
  TASK [Gathering Facts] ******************************************************************************************************************************************************task path: /home/alex/git.sigma/SDG-Tech-DevOps/ansible/301_pb_testing.yml:2
  ok: [demi-win00]
  META: ran handlers
  
  TASK [facts : Gather Facts] *************************************************************************************************************************************************task path: /home/alex/git.sigma/SDG-Tech-DevOps/ansible/roles/facts/tasks/main.yml:14
  ok: [demi-win00]
  
  TASK [debug] ****************************************************************************************************************************************************************task path: /home/alex/git.sigma/SDG-Tech-DevOps/ansible/301_pb_testing.yml:15
  
  ---------REMOVED SOME HOSTVAR OUTPUT FOR BREVITY AND PRIVACY--------
  
  ok: [demi-win00] =&gt; 
    msg: |-
      ansible_architecture: 64-bit
      ansible_bios_date: 03/31/2014
      ansible_bios_version: rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org
      ansible_check_mode: false
      ansible_connection: winrm
      ansible_date_time:
    ......
      ansible_facts:
     ......
      ansible_kernel: 10.0.17763.0
      ansible_lastboot: '2020-08-29 11:07:46Z'
      ansible_machine_id: S-1-5-21-49790847-4020553596-361474921
     ......
  
  ---------REMOVED SOME HOSTVAR OUTPUT FOR BREVITY AND PRIVACY--------
  
  TASK [debug] ****************************************************************************************************************************************************************task path: /home/alex/git.sigma/SDG-Tech-DevOps/ansible/301_pb_testing.yml:18
  fatal: [demi-win00]: FAILED! =&gt; 
    msg: |-
      The task includes an option with an undefined variable. The error was: 'ansible_local' is undefined
    
      The error appears to be in '/home/alex/git.sigma/SDG-Tech-DevOps/ansible/301_pb_testing.yml': line 18, column 7, but may
      be elsewhere in the file depending on the exact syntax problem.
    
      The offending line appears to be:
    
    
          - debug:
            ^ here
  </code></pre>
  <pre><code>ansible 2.9.12
    config file = /etc/ansible/ansible.cfg
    configured module search path = ['/home/alex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
    executable location = /usr/local/bin/ansible
    python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
  </code></pre>
  <p>The ansible Controller is running debian, The remote is Windows Server 2019</p>
  <p>I would expect ansible_local to be populated once setup is run over a valid custom fact, but It doesn't. What am I doing wrong?</p>
  
Tags: <ansible><windows>
Title: The ansible_local var is not being populated when using the setup module to gather custom facts on windows
UserDisplayName: AlexV
ThreadText: # The ansible_local var is not being populated when using the setup module to gather custom facts on windows
  
  (Asked by: username_0 on 2020-09-10)
  
  The ansible\_local var is not being populated when using the setup module to gather custom facts on windows.
  
  **Playbook:**
  
  ```
  ---
  - name: Testing and Debug PB
    hosts: all
    tasks:
    
      - name: Gather Facts
        setup:
          fact_path: 'c:\custom_facts'
  
      - debug:
          msg: "{{ hostvars[inventory_hostname] }}"
  
      - debug:
          msg: "{{ ansible_local }}"
  
  ```
  
  **Contents of "C:\custom\_facts\foo.fact" on remote host:**
  
  ```
  [general]
  asdf=1
  bar=2
  
  ```
  
  Playbook Output:
  
  ```
  ansible-playbook -i inv/dev 301_pb_testing.yml -vv
  ansible-playbook 2.9.12
    config file = /etc/ansible/ansible.cfg
    configured module search path = ['/home/alex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
    executable location = /usr/local/bin/ansible-playbook
    python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
  Using /etc/ansible/ansible.cfg as config file
  
  PLAYBOOK: 301_pb_testing.yml ************************************************************************************************************************************************1 plays in 301_pb_testing.yml
  
  PLAY [Testing and Debug PB] *************************************************************************************************************************************************
  TASK [Gathering Facts] ******************************************************************************************************************************************************task path: /home/alex/git.sigma/SDG-Tech-DevOps/ansible/301_pb_testing.yml:2
  ok: [demi-win00]
  META: ran handlers
  
  TASK [facts : Gather Facts] *************************************************************************************************************************************************task path: /home/alex/git.sigma/SDG-Tech-DevOps/ansible/roles/facts/tasks/main.yml:14
  ok: [demi-win00]
  
  TASK [debug] ****************************************************************************************************************************************************************task path: /home/alex/git.sigma/SDG-Tech-DevOps/ansible/301_pb_testing.yml:15
  
  ---------REMOVED SOME HOSTVAR OUTPUT FOR BREVITY AND PRIVACY--------
  
  ok: [demi-win00] => 
    msg: |-
      ansible_architecture: 64-bit
      ansible_bios_date: 03/31/2014
      ansible_bios_version: rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org
      ansible_check_mode: false
      ansible_connection: winrm
      ansible_date_time:
    ......
      ansible_facts:
     ......
      ansible_kernel: 10.0.17763.0
      ansible_lastboot: '2020-08-29 11:07:46Z'
      ansible_machine_id: S-1-5-21-49790847-4020553596-361474921
     ......
  
  ---------REMOVED SOME HOSTVAR OUTPUT FOR BREVITY AND PRIVACY--------
  
  TASK [debug] ****************************************************************************************************************************************************************task path: /home/alex/git.sigma/SDG-Tech-DevOps/ansible/301_pb_testing.yml:18
  fatal: [demi-win00]: FAILED! => 
    msg: |-
      The task includes an option with an undefined variable. The error was: 'ansible_local' is undefined
    
      The error appears to be in '/home/alex/git.sigma/SDG-Tech-DevOps/ansible/301_pb_testing.yml': line 18, column 7, but may
      be elsewhere in the file depending on the exact syntax problem.
    
      The offending line appears to be:
    
    
          - debug:
            ^ here
  
  ```
  
  ```
  ansible 2.9.12
    config file = /etc/ansible/ansible.cfg
    configured module search path = ['/home/alex/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
    executable location = /usr/local/bin/ansible
    python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
  
  ```
  
  The ansible Controller is running debian, The remote is Windows Server 2019
  
  I would expect ansible\_local to be populated once setup is run over a valid custom fact, but It doesn't. What am I doing wrong?
  
  **Tags:** ansible, windows
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-09-28. Score: 1
  
  According to [documentation](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html):
  
  > NOTE - For windows clients, the results will be added to a variable
  > named after the local file (without extension suffix), rather than ansible\_local.
  
  According to your example it should be in `ansible_foo`, but take into consideration that the files in the path must be PowerShell scripts (with extension .ps1) so maybe `foo.fact` wasn't actually executed.
  
  Hope it helps.
  
  
  ---
  
  