JAESANGPARK
JAESANGPARK

Reputation: 383

What is the exact list of Ansible setup min?

According to the Ansible documentation, the setup module is

This module is automatically called by playbooks to gather useful variables about remote hosts that can be used in playbooks. It can also be executed directly by /usr/bin/ansible to check what variables are available to a host. Ansible provides many facts about the system, automatically.

And there are some parameters which include gather_subset.

If supplied, restrict the additional facts collected to the given subset. Possible values: all, min, hardware, network, virtual, ohai, and facter. Can specify a list of values to specify a larger subset. Values can also be used with an initial ! to specify that that specific subset should not be collected. For instance: !hardware,!network,!virtual,!ohai,!facter. If !all is specified then only the min subset is collected. To avoid collecting even the min subset, specify !all,!min. To collect only specific facts, use !all,!min, and specify the particular fact subsets. Use the filter parameter if you do not want to display some collected facts.

I want to know the exact list of fact that min subset would collect.

Thanks

Upvotes: 3

Views: 2310

Answers (2)

U880D
U880D

Reputation: 12121

It will depend on your environment and setup what is available and can be collected.

You could just have a short test with

---
- hosts: localhost
  become: false

  gather_facts: true
  gather_subset:
    - "min"

  tasks:

  - name: Show Gathered Facts
    debug:
      msg: "{{ ansible_facts }}"

and check the output, in example for a RHEL system the keys are

_ansible_facts_gathered: true
ansible_apparmor:
  status: 
ansible_architecture: 
ansible_cmdline:
  BOOT_IMAGE: 
  LANG: 
  elevator: 
  quiet: 
  rhgb: 
  ro: 
  root: 
ansible_date_time:
  date: ''
  day: ''
  epoch: ''
  hour: 
  iso8601: ''
  iso8601_basic: 
  iso8601_basic_short: 
  iso8601_micro: ''
  minute: ''
  month: ''
  second: ''
  time: 
  tz: 
  tz_offset: ''
  weekday: 
  weekday_number: ''
  weeknumber: ''
  year: ''
ansible_distribution: 
ansible_distribution_file_parsed: 
ansible_distribution_file_path: 
ansible_distribution_file_search_string: 
ansible_distribution_file_variety: 
ansible_distribution_major_version: ''
ansible_distribution_release: 
ansible_distribution_version: ''
ansible_dns:
  nameservers:
  - 
  search:
  - 
ansible_domain: 
ansible_effective_group_id: 
ansible_effective_user_id: 
ansible_env:
  HISTCONTROL: 
  HISTSIZE: ''
  HOME: 
  HOSTNAME: 
  KRB5CCNAME: 
  LANG: 
  LESSOPEN: ''
  LOGNAME: 
  LS_COLORS: 
  MAIL: 
  PATH: 
  PWD: 
  SELINUX_LEVEL_REQUESTED: ''
  SELINUX_ROLE_REQUESTED: ''
  SELINUX_USE_CURRENT_RANGE: ''
  SHELL: 
  SHLVL: ''
  SSH_CLIENT: 
  SSH_CONNECTION: 
  SSH_TTY: 
  TERM: 
  TZ: 
  USER: 
  XDG_RUNTIME_DIR: 
  XDG_SESSION_ID: ''
  _:
ansible_fips:
ansible_fqdn:
ansible_hostname:
ansible_kernel:
ansible_kernel_version: ''
ansible_local: {}
ansible_lsb: {}
ansible_machine:
ansible_machine_id:
ansible_nodename:
ansible_os_family:
ansible_pkg_mgr:
ansible_proc_cmdline:
  BOOT_IMAGE:
  LANG:
  elevator:
  quiet:
  rhgb:
  ro:
  root:
ansible_python:
  executable:
  has_sslcontext:
  type:
  version:
    major: 
    micro: 
    minor: 
    releaselevel:
    serial:
  version_info:
  -
ansible_python_version:
ansible_real_group_id:
ansible_real_user_id:
ansible_selinux:
  config_mode:
  mode:
  policyvers:
  status:
  type:
ansible_selinux_python_present:
ansible_service_mgr:
ansible_ssh_host_key_ecdsa_public:
ansible_ssh_host_key_ed25519_public:
ansible_ssh_host_key_rsa_public:
ansible_system:
ansible_system_capabilities:
- ''
ansible_system_capabilities_enforced: ''
ansible_user_dir:
ansible_user_gecos:
ansible_user_gid:
ansible_user_id:
ansible_user_shell:
ansible_user_uid:
ansible_userspace_architecture:
ansible_userspace_bits: ''
gather_subset:
- min
module_setup: true

For min the /ansible/modules/setup.py tries to gather information from

minimal_gather_subset = frozenset(['apparmor', 'caps', 'cmdline', 'date_time',
                                   'distribution', 'dns', 'env', 'fips', 'local',
                                   'lsb', 'pkg_mgr', 'platform', 'python', 'selinux',
                                   'service_mgr', 'ssh_pub_keys', 'user'])

so that can be considered as

the exact list of fact that min subset would collect.

As one can see, blocks of the information are coming from different modules, in example for ansible_distribution from facts/system/distribution.py.

In my case in example, the module for ansible_env, facts/system/env.py will create keys which can not be found in any other environment.

For more background information of what is collected for specific environments and setups you have a look into /ansible/module_utils/facts.

Further Q&A

Upvotes: 2

Vladimir Botka
Vladimir Botka

Reputation: 68144

Q: "I want to know the exact list of facts that the "min" subset would collect."

A: Run the module separately by ansible. You'll see the list of the facts collected by this module

shell> ansible localhost -m setup -a 'gather_subset=min'

As a side note, the facts differ among the systems. For example, compare the collected minimal facts among FreeBSD and Ubuntu

shell> grep PRETTY_NAME /etc/os-release
PRETTY_NAME="FreeBSD 13.0-RELEASE"

Store the output in a file

shell> ansible localhost -m setup -a 'gather_subset=min' > /scratch/freebsd.json
shell> cat /scratch/freebsd.json
localhost | SUCCESS => {
    "ansible_facts": {

Remove 'localhost | SUCCESS => ` from the file

shell> cat /scratch/freebsd.json
{
    "ansible_facts": {

Create a file with the keys (variables) only

shell> cat freebs.json | jq '.ansible_facts | keys[]' > freebsd_keys.txt

Repeat the procedure in Ubuntu and create ubuntu_keys.txt

shell> grep DISTRIB_DESCRIPTION /etc/lsb-release 
DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"

Diff the files

shell> diff ubuntu_keys.txt freebsd_keys.txt
3d2
< "ansible_cmdline"
6,8d4
< "ansible_distribution_file_parsed"
< "ansible_distribution_file_path"
< "ansible_distribution_file_variety"
25d20
< "ansible_machine_id"
29d23
< "ansible_proc_cmdline"
44,45d37
< "ansible_system_capabilities"
< "ansible_system_capabilities_enforced"
52d43
< "ansible_userspace_architecture"

There are also differences among the Linux distributions. For example, Ubuntu 20.04 and Centos 8

shell> diff ubuntu_keys.txt centos_keys.txt
38d37
< "ansible_ssh_host_key_ecdsa_public_keytype"
40d38
< "ansible_ssh_host_key_ed25519_public_keytype"
42d39
< "ansible_ssh_host_key_rsa_public_keytype"

Upvotes: 1

Related Questions