MM93
MM93

Reputation: 25

ansible: how to access ansible_env when gather_facts: false

I would like to have a minimal fact gathering that would only. I'm actually only interested in accessing the variables defined in ansible_env.

I've tried to use the setup module with filter: ansible_env and gather_subset: min but It didn't work for me...

any hint would be greatly appreciated

Thanks!

Upvotes: 2

Views: 5310

Answers (2)

David
David

Reputation: 291

Instead of creating a playbook just for that, you can execute an Ansible command like the following, in order to retrieve specific facts:

ansible <hostname> -m setup -a "filter=ansible_distribution"

Source

Upvotes: 3

NoNoNo
NoNoNo

Reputation: 168

I report below a minimal example:

- hosts: localhost
  gather_facts: false
  tasks:
    - setup:
        filter: ansible_env
    - debug:
        var=ansible_env

Upvotes: 1

Related Questions