{"id":2500,"date":"2023-02-23T16:20:11","date_gmt":"2023-02-23T16:20:11","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=2500"},"modified":"2023-02-23T16:20:13","modified_gmt":"2023-02-23T16:20:13","slug":"ansible-configuration-ansible-cfg","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2023\/02\/23\/ansible-configuration-ansible-cfg\/","title":{"rendered":"Ansible Configuration: `ansible.cfg`"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><img decoding=\"async\" width=\"97\" height=\"91\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2023\/02\/an-config.png\" alt=\"\" class=\"wp-image-2501\"\/><\/figure>\n<\/div>\n\n\n<p><code>ansible.cfg<\/code> is the main configuration file for Ansible. It is used to customize Ansible&#8217;s behavior and includes a wide range of options, including the location of inventory files, the default SSH user, and the path to the module library.<\/p>\n\n\n\n<p>The file can be placed in various locations, such as the current directory, user&#8217;s home directory, <code>\/etc\/ansible\/<\/code>, and <code>\/etc\/ansible\/conf.d\/<\/code>.<\/p>\n\n\n\n<p>Here are some frequently used properties in <code>ansible.cfg<\/code>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>inventory<\/code>: This specifies the location of the inventory file. By default, Ansible looks for an inventory file at <code>\/etc\/ansible\/hosts<\/code>.<\/li>\n\n\n\n<li><code>remote_user<\/code>: This specifies the default remote user to use when running Ansible commands. By default, this is set to the current user.<\/li>\n\n\n\n<li><code>become<\/code>: This specifies whether to use privilege escalation or not. If set to <code>true<\/code>, Ansible will attempt to elevate privileges using <code>sudo<\/code> or <code>su<\/code>.<\/li>\n\n\n\n<li><code>become_user<\/code>: This specifies the user to become when using privilege escalation.<\/li>\n\n\n\n<li><code>become_method<\/code>: This specifies the method to use for privilege escalation. The default is <code>sudo<\/code>.<\/li>\n\n\n\n<li><code>module_name_mapper<\/code>: This allows you to specify a custom mapping of module names to file names.<\/li>\n\n\n\n<li><code>library<\/code>: This specifies the directory where Ansible looks for modules. By default, Ansible looks for modules in <code>\/usr\/share\/ansible\/<\/code>.<\/li>\n\n\n\n<li><code>forks<\/code>: This specifies the maximum number of parallel processes to use when executing tasks. The default is 5.<\/li>\n\n\n\n<li><code>gathering<\/code>: This specifies the method for gathering facts. By default, it is set to <code>smart<\/code>.<\/li>\n\n\n\n<li><code>fact_caching<\/code>: This specifies whether to use fact caching or not. Fact caching can improve performance by caching facts between playbook runs.<\/li>\n<\/ol>\n\n\n\n<p>Here&#8217;s an example <code>ansible.cfg<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-small-font-size\"><code>&#91;defaults]\ninventory = \/etc\/ansible\/hosts\nremote_user = ansible\nbecome = true\nbecome_user = root\nmodule_name_mapper = custom_module_name_mapper\nlibrary = \/usr\/local\/lib\/ansible\/modules\nforks = 10\ngathering = smart\nfact_caching = redis\nfact_caching_timeout = 300<\/code><\/pre>\n\n\n\n<p>In this example, we&#8217;ve specified the inventory file location, set the default remote user to <code>ansible<\/code>, enabled privilege escalation, set the privilege escalation user to <code>root<\/code>, specified a custom module name mapper, set the module library location to <code>\/usr\/local\/lib\/ansible\/modules<\/code>, increased the maximum number of forks to 10, set the fact gathering method to <code>smart<\/code>, and enabled fact caching with a timeout of 300 seconds.<\/p>\n\n\n\n<p>Overall, <code>ansible.cfg<\/code> provides a lot of flexibility in configuring Ansible&#8217;s behavior to suit your needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ansible.cfg is the main configuration file for Ansible. It is used to customize Ansible&#8217;s behavior and includes a wide range of options, including the location of inventory files, the default SSH user, and the path to the module library. The file can be placed in various locations, such as the current directory, user&#8217;s home directory, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2501,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[278,287],"class_list":["post-2500","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technical","tag-ansible","tag-configuration"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=2500"}],"version-history":[{"count":1,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2500\/revisions"}],"predecessor-version":[{"id":2502,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2500\/revisions\/2502"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/2501"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=2500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=2500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=2500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}