Bookmark this page

Chapter 4.  Working with Ansible Configuration Settings

Abstract

Goal

Examine and adjust the configuration of Ansible and automation content navigator to simplify development and to troubleshoot issues.

Objectives
  • Browse the current Ansible configuration by using automation content navigator.

  • Change configuration settings for automation content navigator with its configuration file, and determine where the configuration file is located.

Sections
  • Examining the Ansible Configuration with Automation Content Navigator  (and Guided Exercise)

  • Configuring Automation Content Navigator  (and Guided Exercise)

Lab
  • Working with Ansible Configuration Settings

Examining the Ansible Configuration with Automation Content Navigator

Objectives

  • Browse the current Ansible configuration by using automation content navigator.

Inspecting the Ansible Configuration in Interactive Mode

The ansible-navigator config command displays the current Ansible configuration used by the ansible-navigator run command in interactive mode. You can also use ansible-navigator config to determine the source of current ansible-navigator configuration settings.

Knowing the source of ansible-navigator configuration settings can help you determine why a particular setting in your current Ansible configuration has a specific value.

For example, configuration settings can come from the following sources:

  • Specific environment variables.

  • A configuration file specified by the ANSIBLE_CONFIG environment variable.

  • Hard-coded default values.

You can use the ansible-navigator config command to examine your configuration, retrieve the current and default configuration settings, and access documentation for each configuration parameter.

The ansible-navigator config command is useful for troubleshooting configuration issues. For example, this command can help you locate the issue when a configuration parameter does not work as expected or when Ansible does not take a parameter into account. It also displays the actual value that Ansible uses for each parameter and from which source it retrieves that value, configuration file, or environment variable.

The following screen capture shows the output of the ansible-navigator config command:

    Name                      Default   Source                  Current
  0│Action warnings           True      default                 True
  1│Agnostic become prompt    True      default                 True
...output omitted...
 44│Default ask pass          True      default                 False
 45│Default ask vault pass    True      default                 False
 46│Default become            False     /home/.../ansible.cfg   True
 47│Default become ask pass   False     /home/.../ansible.cfg   False
 48│Default become exe        True      default   None
...output omitted...
 61│Default forks             False     env                     100
 62│Default gathering         True      default                 implicit
...output omitted...

In the preceding example, each line describes an Ansible configuration parameter. The columns provide the following information:

Name

The Name column displays the internal names that Ansible uses for parameters. These names are not the same as the names that you use in the ansible.cfg configuration file. For example, the Default become parameter corresponds to the become parameter in the ansible.cfg configuration file. You can display that name mapping by typing the number of the parameter you are interested in, prefixed by a colon if that number is greater than 9.

Default

The Default column indicates whether the parameter is using its default value (when True) or is using a value that you explicitly set in an ansible.cfg configuration file or through an environment variable (when False). To help you identify changed parameters, the ansible-navigator command displays default parameter settings in green and those that have changed from the defaults in yellow.

Source

When a parameter is not using its default value, the Source column indicates how the parameter has been set. The Source column gives the full path to the configuration file from which Ansible retrieved the parameter's value. If the column displays the env keyword, then an environment variable set that parameter's value.

Current

The Current column displays the actual value of the parameter.

Searching for Specific Configuration Parameters

The filter function of the ansible-navigator command enables you to search for specific parameters. Type :filter (or :f) followed by a regular expression to perform a search in the command output. For example, to locate the Default forks parameter, you could use the :f forks filter command.

This function is not limited to searching for parameter names. You can search for any pattern in the ansible-navigator output. For example, you can use the :f ansible.cfg filter command to list all the parameters defined in an ansible.cfg configuration file. Remember that regular expressions are case-sensitive.

Accessing Parameter Details

To get the details of a parameter, type its number, prefixed by a colon if that number is greater than 9. The following example displays the details of the Default forks parameter.

Default forks (current: 100)  (default: 5)
 0│---
 1│current_config_file: None
 2│current_value: 100 1
 3│default: false
 4│default_value: 5 2
 5│description: Maximum number of forks Ansible will use to execute tasks on target hosts.
 6│env:
 7│- name: ANSIBLE_FORKS 3
 8│ini:
 9│- key: forks 4
10│  section: defaults
11│name: Default forks
12│option: DEFAULT_FORKS
13│source: env
14│type: integer
15│via: ANSIBLE_FORKS

1

The actual parameter value is 100.

2

The parameter's default value is 5. Ansible only uses that default value if you do not override it in the ansible.cfg configuration file or through the environment variable.

3

The name of the environment variable that you can use to set the parameter value is ANSIBLE_FORKS.

4

You can also set the parameter's value in an ansible.cfg configuration file by setting the forks parameter in the [defaults] section.

Inspecting the Local Configuration

By default, the ansible-navigator command uses an automation execution environment to perform its tasks. If your Ansible project does not provide the ansible.cfg configuration file, then the ansible-navigator command uses the /etc/ansible/ansible.cfg file that the automation execution environment supplies.

The command does not use the /etc/ansible/ansible.cfg or the ~/.ansible.cfg configuration files from the local system when you use automation execution environments. To process those local files, use the --execution-environment false (or --ee false) option to prevent the command from using automation execution environments.

Important

Because you use ansible-navigator to run your playbook with an automation execution environment instead of the local control node environment, you usually inspect the automation execution environment configuration.

Inspecting the Ansible Configuration in Standard Output Mode

In addition to its interactive mode, the ansible-navigator config command can list the configuration parameters on the standard output and then exit. Add the --mode stdout (or -m stdout) option to the command to use that mode.

In non-interactive mode, the command works like the ansible-config command and requires a subcommand:

  • The list subcommand lists all the Ansible configuration parameters. The resulting output is a static list that describes each parameter. The command does not report the current parameter values.

  • The dump subcommand lists all the Ansible configuration parameters and their current values.

  • The view subcommand displays the contents of the ansible.cfg configuration file that Ansible is using. This subcommand is helpful to confirm that Ansible is using the expected configuration file.

The following example lists the configuration parameters and their current values:

[user@host ansible-project]$ ansible-navigator config -m stdout dump
ACTION_WARNINGS(default) = True
AGNOSTIC_BECOME_PROMPT(default) = True
...output omitted...
DEFAULT_ASK_VAULT_PASS(default) = False
DEFAULT_BECOME(/home/user/ansible-project/ansible.cfg) = True
DEFAULT_BECOME_ASK_PASS(/home/user/ansible-project/ansible.cfg) = False
DEFAULT_BECOME_EXE(default) = None
...output omitted...
DEFAULT_FORCE_HANDLERS(default) = False
DEFAULT_FORKS(env: ANSIBLE_FORKS) = 100
DEFAULT_GATHERING(default) = implicit
...output omitted...

Revision: do374-2.2-82dc0d7