Ansible Playbooks

Welcome to another insightful blog post from #TrainWithShubham! Today, we’re diving into the world of Ansible, a powerful tool for automating tasks in your DevOps pipeline. We’ll cover some essential Ansible playbooks that you can use to manage your servers, create files, add users, and install Docker. Let’s get started!

Update All the Servers

Keeping your servers up-to-date is crucial for security and performance. With Ansible, you can easily upgrade all the packages across multiple servers in one go. Here’s how you can do it:

ansible all -m apt -a "upgrade=yes update_cache=yes cache_valid_time=86400" --become

Explanation:

  • all: This targets all hosts in your Ansible inventory.
  • -m apt: Specifies that we are using the apt module, which is used to manage packages on Debian-based systems.
  • -a: The arguments passed to the apt module.
  • upgrade=yes: This option upgrades all installed packages to their latest versions.
  • update_cache=yes: This option ensures the package cache is updated before upgrading.
  • cache_valid_time=86400: This sets the cache validity time to 24 hours.
  • –become: This allows Ansible to execute the command with elevated privileges (sudo).

Categorized in:

DevOps,