Monday, February 13, 2023

Customize Ansible Behaviour

The default location of ansible.cfg file is /etc/ansible/ansible.cfg

The ansible.cfg file is the main configuration file for Ansible. It specifies the configuration options for an Ansible deployment. The sections in the ansible.cfg file include:

  1. Default Settings: This section contains default settings for Ansible such as the location of the inventory file, the library path, and the SSH user.

  2. Inventory: This section contains options for configuring the inventory file, including the host file, the pattern to match hosts, and the SSH user.

  3. Privilege Escalation: This section contains options for privilege escalation, including the default become method, the default become user, and the default become flags.

  4. Connections: This section contains options for configuring the connection method, including the transport, the connection timeout, and the retries.

  5. Module Configuration: This section contains options for configuring the module behavior, including the library path, the default module path, and the maximum module execution time.

  6. Plugins: This section contains options for configuring the plugins, including the callback plugin directory and the filter plugin directory.

  7. SSH Options: This section contains options for configuring the SSH connection, including the SSH user, the SSH key file, and the SSH timeout.

  8. Output Options: This section contains options for configuring the output of Ansible, including the verbosity, the color output, and the output format.

  9. Strategy Options: This section contains options for configuring the strategy for executing tasks, including the strategy, the forking, and the strategy plugins.

Each of these sections can be customized to meet your specific needs and requirements. It's important to note that these settings can be overridden by settings in other configuration files or on the command line.


here's an example of a complete ansible.cfg file with all the sections and options I mentioned:


# Default Settings [defaults] inventory = ./inventory library = /usr/share/ansible/library remote_user = ansible # Inventory [inventory] enable_plugins = ini, virtualbox, yaml host_pattern = ^[a-zA-Z0-9._-]+$ # Privilege Escalation [privilege_escalation] become = True become_method = sudo become_user = root become_ask_pass = False # Connections [connection] transport = ssh timeout = 10 retries = 3 # Module Configuration [module_defaults] library = /usr/share/ansible/library module_path = /usr/share/ansible/modules module_timeout = 30 # Plugins [plugins] callback_whitelist = timer filter_plugins = /usr/share/ansible/plugins/filter # SSH Options [ssh_connection] ssh_user = ansible ssh_key_file = ~/.ssh/id_rsa ssh_timeout = 10 # Output Options [output] verbosity = 2 colored = True format = json # Strategy Options [strategy] strategy = linear forks = 5 strategy_plugins = /usr/share/ansible/plugins/strategy






No comments:

Post a Comment

Menu Creation

 <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="view...