1. Install Ansible
/etc/ansible/hosts
[webserver]
It is the group name of the server, and the name can be customized. Put the servers with the same characteristics in a group, which is convenient for batch operation later
20.189.72.94
Server address, which can be a domain name
ansible_ssh_user
The user name used to log in, I use the root login for convenience
ansible_ssh_port
ssh port, if you are not using 22, you can specify this parameter. If it is 22, you can omit
ansible_ssh_pass
Login password
ansible_ssh_private_key_file
If you are using a key to log in, this parameter can specify the address of the key file
3. Allow Password Login
vi /etc/ansible/ansible.cfg
4. Execute batch commands
webserver
It is the group name of the server group defined in hosts above.
-m shell
Specify ansible to execute the shell module. There are many modules in ansible, and tutorials will be written in the future. Here we use the shell module to execute shell commands as an example.
-a "ping 1.1.1.1 -c 3"
-a specifies the command to be executed later, here is ping 1.1.1.1 3 times
/home/1.sh
wrote the script in two lines
all
all means to execute all servers in the hosts file.
-m script
Instructions for using ansible's script module
-a "/home/1.sh"
-a followed by the location of the script to be executed
References
https://www.91yun.co/archives/42901
via Blogger https://ift.tt/3mX4Pca
November 05, 2020 at 01:33PM Network