Ansible Commands: From Basics to Mastery (Part 5)

Ansible Commands: From Basics to Mastery (Part 5)

Ansible Commands Ansible has multiple commands, each serving different functions. Below are some commonly used commands and their parameters. Common Commands # Set the ansible configuration file ansible-config # View ansible related modules and module documentation ansible-doc # View ansible's inventory ansible-inventory # Execute ad-hoc tasks ansible # Execute ansible playbooks ansible-playbook # Set ansible … Read more

Practical Automation in Operations: Managing Thousands of Servers with Ansible and Python

Practical Automation in Operations: Managing Thousands of Servers with Ansible and Python

At three o’clock that morning, I was dealing with an unexpected online failure with my colleagues, where dozens of service nodes needed urgent configuration updates. Manual operation? Not realistic. Writing a temporary script? Too slow. At that moment, I remembered the Ansible + Python automation framework I had configured earlier. Within three minutes, all node … Read more

Basic Usage of Ansible Playbook

Basic Usage of Ansible Playbook

Introduction to Ansible Playbook A Playbook is a component of Ansible used for configuration management. While Ansible’s AD-Hoc command functionality is powerful and can accomplish some basic configuration management tasks, AD-Hoc commands cannot support the configuration management of complex environments. In our practical use of Ansible, most of the time is spent writing Playbooks. In … Read more

Using Ansible Playbook to Copy Files from Remote Server

Using Ansible Playbook to Copy Files from Remote Server

Copy files from a remote server to a local computer. This can be accomplished using the Ansible fetch module. This is useful when you want to copy certain log files from a remote server to your local machine. By default, a directory named after each host you are connecting to will be created in the … Read more

Ansible Inventory Management: From Basics to Advanced Usage (Part 4)

Ansible Inventory Management: From Basics to Advanced Usage (Part 4)

Ansible Inventory The inventory is used to define which hosts are managed by Ansible. The inventory supports the following formats: • IP addresses • Hostnames • Ranges (<span>server[b:c]</span>) • Host groups (<span>webserver</span>) • Subgroups (<span>lnmp:children</span>) Inventory 172.25.250.10 [webserver] server[b:c] [mysql] 172.25.250.1[3:4] [lnmp:children] webserver mysql • Directly defining a hostname or address, currently <span>172.25.250.10</span> does not … Read more

Using Ansible Playbook to Copy Multiple Files to Target Server

Using Ansible Playbook to Copy Multiple Files to Target Server

Using with_items to Copy Multiple Files/Directories If you want to copy multiple files, you can use with_items to iterate over them. — – hosts: all remote_user: root gather_facts: false tasks: – name : copy file copy: src: /root/{{item}} dest: /usr/local/apps/ with_items: [’45.txt’, ‘run.sh’,’node_exporter.tar.gz’] [root@ansible ~]# ansible-playbook -C copy.yaml [root@ansible ~]# ansible-playbook copy.yaml Check the copied … Read more

Ansible Installation: From Beginner to Abandonment (Part 2)

Ansible Installation: From Beginner to Abandonment (Part 2)

Ansible Installation There are three installation methods for Ansible: Source Installation, Distribution Installation, and Python Installation. When using either Distribution Installation or Python Installation, there are two installation packages for Ansible, which are as follows: • <span>ansible-core</span>: A minimal language and runtime package that includes a set of built-in modules and plugins. • <span>ansible</span>: A … Read more

Ansible Configuration File: From Basics to Advanced

Ansible Configuration File: From Basics to Advanced

Ansible Configuration File Ansible looks for a file named <span>ansible.cfg</span> as its configuration file. [root@ansible ansible]# ansible –version ansible [core 2.16.3] config file = /root/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.12/site-packages/ansible_core-2.16.3-py3.12.egg/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /usr/local/bin/ansible python version = 3.12.8 (main, Dec 12 2024, … Read more

Ansible Playbook: Copying Multiple Files

Ansible Playbook: Copying Multiple Files

1. Copying a Single File to the Target Server [root@Jenkins copymodule]# cat copy.yml—– hosts: allremote_user: rootgather_facts: falsetasks:– name: “Copy file from host to target server”copy:src: “/root/ansible/luyan/copymodule/copytest1.txt”dest: “/opt/copymodule”owner: rootgroup: rootmode: 755 2. Copying Multiple Files to the Target Server [root@Jenkins copymodule]# cat copyduogewenjian.yml—– hosts: allremote_user: rootgather_facts: falsetasks:– name: “Copy files from host to target server”copy:src: “{{ … Read more

Ansible: From Introduction to Abandonment (Part 1)

Ansible: From Introduction to Abandonment (Part 1)

Introduction to Ansible Ansible is an open-source automation tool developed by Red Hat for: • Configuration Management • Application Deployment • Automated Task Execution • Batch Operations on Multiple Servers Its main features are: Agentless + SSH-based connection + YAML scripting (high readability). Why Choose Ansible? Feature Description ✅ Agentless No agent installation required on … Read more