Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Network Automation Cookbook

You're reading from   Network Automation Cookbook Proven and actionable recipes to automate and manage network devices using Ansible

Arrow left icon
Product type Paperback
Published in Apr 2020
Publisher Packt
ISBN-13 9781789956481
Length 482 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
 Okasha Okasha
Author Profile Icon Okasha
Okasha
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Building Blocks of Ansible 2. Managing Cisco IOS Devices Using Ansible FREE CHAPTER 3. Automating Juniper Devices in the Service Providers Using Ansible 4. Building Data Center Networks with Arista and Ansible 5. Automating Application Delivery with F5 LTM and Ansible 6. Administering a Multi-Vendor Network with NAPALM and Ansible 7. Deploying and Operating AWS Networking Resources with Ansible 8. Deploying and Operating Azure Networking Resources with Ansible 9. Deploying and Operating GCP Networking Resources with Ansible 10. Network Validation with Batfish and Ansible 11. Building a Network Inventory with Ansible and NetBox 12. Simplifying Automation with AWX and Ansible 13. Advanced Techniques and Best Practices for Ansible 14. Other Books You May Enjoy

Customizing Ansible's settings

Ansible has many setting that can be adjusted and controlled using a configuration file called ansible.cfg. This file has multiple options that control many aspects of Ansible, including how Ansible looks and how it connects to managed devices. In this recipe, we will outline how to adjust some of these default settings.

How to do it...

  1. Create a new file called ansible.cfg, as shown here:
[defaults]
inventory=hosts
vault_password_file=decryption_password
gathering=explicit

How it works...

By default, Ansible's settings are controlled by the ansible.cfg file located in the /etc/ansible directory. This is the default configuration file for Ansible that controls how Ansible interacts with managed nodes. We can edit this file directly. However, this will impact any playbook that we will use on the Ansible control machine, as well as any user on this machine. A more flexible and customized option is to include a file named ansible.cfg in the project directory and this includes all the options that you need to modify from their default parameters. In the preceding example, we outline only a small subset of these options, as shown here:

  • inventory: This option modifies the default inventory file that Ansible searches in order to find its inventory (by default, this is /etc/ansible/hosts). We adjust this option in order to let Ansible use our inventory file and stop using the -i operator to specify our inventory during each playbook run.
  • vault_password_file: This option sets the file that has the secret password for encrypting and decrypting ansible-vault secrets. This option removes the need to run Ansible playbooks with the --vault-id operator when using ansible-vault-encrypted variables.

  • gathering = explicit: By default, Ansible runs a setup module to gather facts regarding the managed nodes while the playbook is running. This setup module is not compatible with network nodes since this module requires a Python interpreter on the managed nodes. By setting fact gathering to explicit, we disable this default behavior.

See also...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images