I've written a GitHub repo to demo using local_facts here:  
https://github.com/dmccuk/ansible_local_facts

The bit you need to do is this (which is also part of the demo):

- name: local facts
  debug: var=ansible_local
  notify:
  - reload facts

- name: reload facts
  setup: filter=ansible_local



On Thursday, 2 April 2020 03:16:34 UTC+1, Rajesh wrote:
>
> Hi All,
>
> I created a custom facts playbook. But I am getting an error when I run. I 
> could not figure out why?
>
> *Playbook*
>
> - name: Create a custom facts file
>   hosts: database
>   become: true
>   become_user: root
>   gather_facts: true
>   tasks:
>     - name: Create a custom facts directory
>       file:
>         path: /etc/ansible/facts.d
>         state: directory
>
>     - name: Create a custom facts
>       template:
>         src: templates/custom.fact.j2
>         dest: /etc/ansible/facts.d/custom.fact
>
>     - name: Print ansible_local
>       debug: var=ansible_local
>     - name: Print the custom facts value
>       debug:
>         msg: "{{ ansible_local.custom.sample_exam }}"
>
> *Template file*
>
> [automation@workstation plays]$ cat templates/server_list.j2 
> {% for host in groups['all'] %}
> {{ hostvars[host]['ansible_facts']['fqdn'] }}
> {% endfor %}
>
> [automation@workstation plays]$ 
>
> [automation@workstation plays]$ ansible-playbook facts.yml 
>
> PLAY [Create a custom facts file] 
> **********************************************************************************************************************************************************************************************************
>
> TASK [Gathering Facts] 
> *********************************************************************************************************************************************************************************************************************
> fatal: [ansible5]: FAILED! => {"ansible_facts": {}, "changed": false, 
> "failed_modules": {"setup": {"ansible_facts": 
> {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "cmd": 
> "/etc/ansible/facts.d/custom.fact", "failed": true, "invocation": 
> {"module_args": {"fact_path": "/etc/ansible/facts.d", "filter": "*", 
> "gather_subset": ["all"], "gather_timeout": 10}}, "msg": "[Errno 8] Exec 
> format error: b'/etc/ansible/facts.d/custom.fact'", "rc": 8}}, "msg": "The 
> following modules failed to execute: setup\n"}
>
> PLAY RECAP 
> *********************************************************************************************************************************************************************************************************************************
> ansible5                   : ok=0    changed=0    unreachable=0    
> failed=1    skipped=0    rescued=0    ignored=0   
>
> [automation@workstation plays]$ 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/edc4ccb4-6803-4b89-a000-049b59e305fd%40googlegroups.com.

Reply via email to