On Tue, 27 Oct 2020 03:26:02 -0700 (PDT)
Hiero-nymo <
jer.m...@gmail.com> wrote:
> I'm taking the hostname in playbook via set_stats but I cannot check if my
> variable are correct.
> ---
> - hosts: all
> gather_facts: yes
>
> pre_tasks:
> - name: get the hostname
> set_stats:
> data:
> inv_host: "{{ inventory_hostname }}"
>
> - name: get result
> debug:
> msg: "{{ inv_host}}"
> [...]
> And here's the result:
> fatal: [xx.xx.xx.xx]: FAILED! => ... The error was: 'inv_host' is undefined
The variable "inv_host" is valid in the context of custom status
only. The module set_stats works as expected. For example
shell> cat pb.yml
- hosts: localhost
tasks:
- set_stats:
data:
inv_host: "{{ inventory_hostname }}"
shell> ANSIBLE_SHOW_CUSTOM_STATS=True ansible-playbook pb.yml
...
PLAY RECAP **************************************************
localhost: ok=2 changed=0 unreachable=0 failed=0 skipped=0
rescued=0 ignored=0
CUSTOM STATS: ***********************************************
RUN: inv_host: localhost
--
Vladimir Botka