In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the meaning of peer-to-peer command in Ansible. It is very detailed and has a certain reference value. Friends who are interested must finish it!
What is a peer-to-peer ad-hoc command?
Point-to-point commands are used to automate tasks on one or more controlled nodes. It is very simple, but not reusable. It uses the / usr/bin/ansible binary to perform all operations.
Peer-to-peer commands are best suited for one-time tasks. For example, if you want to check whether a specified user is available, you can use an one-line command without writing a screenplay.
Why do you need to know about peer-to-peer commands?
Peer-to-peer commands demonstrate the simplicity and power of Ansible. Starting with version 2.9, it supports 3389 modules, so you need to know and learn the list of Ansible modules to use on a regular basis.
If you are new to Ansible, you can easily practice these modules and parameters with the help of peer-to-peer commands.
The concepts you have learned here will be transplanted directly into the script.
General syntax for point-to-point commands:
Ansible [mode]-m [module]-a "[module options]"
The point-to-point command consists of four parts, with details as follows:
Section describes ansible command mode input list or specify group module to run specified module name module options specify how module parameters use the Ansible manifest file
If you use Ansible's default manifest file / etc/ansible/hosts, you can call it directly. Otherwise you can use the-I option to specify the path to the Ansible manifest file.
What is a pattern and how to use it?
Ansible mode can refer to a host, an IP address, a list group, a group of hosts, or all hosts in the list. It allows you to run commands and scripts on them. Patterns are very flexible, and you can use them as needed.
For example, you can exclude hosts, use wildcards or regular expressions, and so on.
The following table describes common patterns and usage. However, if it doesn't meet your needs, you can use variables in the schema with the-e parameter in ansible-playbook.
Describe the pattern goal all hosts all (or *) run Ansible on all servers in the list one host host1 only runs Ansible multiple hosts host1:host2 (or host1) for a given host Host2) run Ansible on the above multiple hosts A set of webservers runs all hosts in the Ansible multi-group webservers:dbserverswebservers in the webservers group plus all hosts in the dbservers exclusion group webserversParticipatlantawebservers the intersection between all host groups except atlanta is also in any host of staging what is the Ansible module What did it do?
A module, also known as a "task plug-in" or a "library plug-in", is a set of code units that can perform specified tasks on a remote host directly or through a script.
Ansible executes the specified module on the remote destination node and collects its return values.
Each module supports multiple parameters to meet the needs of users. With the exception of a few modules, almost all modules take the key=value parameter. You can add multiple parameters with spaces at a time, and the command or shell module will run the string you entered directly.
We will add a table that contains the most commonly used Module options parameters.
List all available modules and run the following command:
$ansible-doc-l
Run the following command to read the documentation for the specified module:
$ansible-doc [module] 1) how to use Ansible to list the contents of a directory on Linux
You can do this using the Ansible command module, as shown below. We listed the contents of the daygeek user home directory on node1.2g.lab and nod2.2g.lab* remote servers.
$ansible web-m command-a "ls-lh / home/daygeek" node1.2g.lab | CHANGED | rc=0 > > total 12Kdrwxr-xr-x. 2 daygeek daygeek 6 Feb 15 2019 Desktopdrwxr-xr-x. 2 daygeek daygeek 6 Feb 15 2019 Documentsdrwxr-xr-x. 2 daygeek daygeek 6 Feb 15 2019 Downloadsdrwxr-xr-x. 2 daygeek daygeek 6 Feb 15 2019 Music-rwxr-xr-x. 1 daygeek daygeek 159 Mar 4 2019 passwd-up.shdrwxr-xr-x. 2 daygeek daygeek 6 Feb 15 2019 Picturesdrwxr-xr-x. 2 daygeek daygeek 6 Feb 15 2019 Publicdrwxr-xr-x. 2 daygeek daygeek 6 Feb 15 2019 Templates-rwxrwxr-x. 1 daygeek daygeek 138 Mar 10 2019 user-add.sh-rw-rw-r--. 1 daygeek daygeek 18 Mar 10 2019 user-list1.txtdrwxr-xr-x. 2 daygeek daygeek 6 Feb 15 2019 Videos node2.2g.lab | CHANGED | rc=0 > > total 0drwxr-xr-x. 2 daygeek daygeek 6 Nov 9 09:55 Desktopdrwxr-xr-x. 2 daygeek daygeek 6 Nov 9 09:55 Documentsdrwxr-xr-x. 2 daygeek daygeek 6 Nov 9 09:55 Downloadsdrwxr-xr-x. 2 daygeek daygeek 6 Nov 9 09:55 Musicdrwxr-xr-x. 2 daygeek daygeek 6 Nov 9 09:55 Picturesdrwxr-xr-x. 2 daygeek daygeek 6 Nov 9 09:55 Publicdrwxr-xr-x. 2 daygeek daygeek 6 Nov 9 09:55 Templatesdrwxr-xr-x. 2 daygeek daygeek 6 Nov 9 09:55 Videos2) how to use Ansible to manage files in Linux
The copy module of Ansible copies files from the local system to the remote system. Use the Ansible command module to move or copy files to a remote computer.
$ansible web-m copy-a "src=/home/daygeek/backup/CentOS7.2daygeek.com-20191025.tar dest=/home/u1"-- become node1.2g.lab | CHANGED = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": true, "checksum": "ad8aadc0542028676b5fe34c94347829f0485a8c", "dest": "/ home/u1/CentOS7.2daygeek.com-20191025.tar", "gid": 0 "group": "root", "md5sum": "ee8e778646e00456a4cedd5fd6458cf5", "mode": "0644", "owner": "root", "secontext": "unconfined_u:object_r:user_home_t:s0", "size": 30720, "src": "/ home/daygeek/.ansible/tmp/ansible-tmp-1579726582.474042-118186643704900/source", "state": "file" "uid": 0} node2.2g.lab | CHANGED = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/libexec/platform-python"}, "changed": true, "checksum": "ad8aadc0542028676b5fe34c94347829f0485a8c", "dest": "/ home/u1/CentOS7.2daygeek.com-20191025.tar", "gid": 0, "group": "root", "md5sum": "ee8e778646e00456a4cedd5fd6458cf5" "mode": "0644", "owner": "root", "secontext": "unconfined_u:object_r:user_home_t:s0", "size": 30720, "src": "/ home/daygeek/.ansible/tmp/ansible-tmp-1579726582.4793239-237229399335623/source", "state": "file", "uid": 0}
We can run the following command to verify:
$ansible web-m command-a "ls-lh / home/u1"-- become node1.2g.lab | CHANGED | rc=0 > > total 36K Murray 1 root root 30K Jan 22 14:56 CentOS7.2daygeek.com-20191025.tar-rw-r--r--. 1 root root 25 Dec 9 03:31 user-add.sh node2.2g.lab | CHANGED | rc=0 > > total 36K, RW, RW, RMI, RMI. 1 root root 30K Jan 23 02:26 CentOS7.2daygeek.com-20191025.tar-rw-rw-r--. 1 u1 u1 18 Jan 23 02:21 magi.txt
To copy files from one location to another on the remote computer, use the following command:
$ansible web-m command-a "cp / home/u2/magi/ansible-1.txt / home/u2/magi/2g"-- become
To move the file, use the following command:
$ansible web-m command-a "mv / home/u2/magi/ansible.txt / home/u2/magi/2g"-- become
Create a new file called ansible.txt under the U1 user directory and run the following command:
$ansible web-m file-a "dest=/home/u1/ansible.txt owner=u1 group=u1 state=touch"-- become
Create a new directory called magi under the U1 user directory and run the following command:
$ansible web-m file-a "dest=/home/u1/magi mode=755 owner=u2 group=u2 state=directory"-- become
Change the ansible.txt* file permissions under the U1 user directory to 777 and run the following command:
$ansible web-m file-a "dest=/home/u1/ansible.txt mode=777"-- become
Delete the ansible.txt file under the U1 user directory and run the following command:
$ansible web-m file-a "dest=/home/u2/magi/ansible-1.txt state=absent"-- become
Use the following command to delete the directory, which recursively deletes the specified directory:
$ansible web-m file-a "dest=/home/u2/magi/2g state=absent"-- become3) user management
You can easily perform user management activities using Ansible. For example, create, delete, and add users to a group.
$ansible all-m user-a "name=foo password= [crypted password here]"
Run the following command to delete the user:
$ansible all-m user-a "name=foo state=absent" 4) Management Pack
You can easily manage installation packages using the appropriate Ansible package manager module. For example, we will use the yum module to manage software packages on the CentOS system.
Install the latest Apache (httpd):
$ansible web-m yum-a "name=httpd state=latest"
Uninstall the Apache (httpd) package:
$ansible web-m yum-a "name=httpd state=absent" 5) Management Services
Any service can be managed on Linux using the following Ansible module commands.
Stop the httpd service:
$ansible web-m service-a "name=httpd state=stopped"
Start the httpd service:
$ansible web-m service-a "name=httpd state=started"
Restart the httpd service:
$ansible web-m service-a "name=httpd state=restarted" is all the content of the article "what is the meaning of peer-to-peer commands in Ansible". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.