Installation of operation and maintenance automation artifact ansible (1)
Operation and maintenance automation artifact ansible installation (1) installation and deployment yum install ansible through the rpm-ql command we can see that ansible has a lot of subcommands and their installation location. [root@master01 ~] # rpm-ql ansible | grep bin/usr/bin/ansible/usr/bin/ansible-2/usr/bin/ansible-2.7/usr/bin/ansible-config/usr/bin/ansible-connection/usr/bin/ansible-console/usr/bin/ansible-console-2/usr/bin/ansible-console-2.7/usr/bin/ansible-doc/usr/bin/ansible-doc-2/usr/bin/ansible-doc-2.7/usr/bin/ansible -galaxy/usr/bin/ansible-galaxy-2/usr/bin/ansible-galaxy-2.7/usr/bin/ansible-inventory/usr/bin/ansible-playbook/usr/bin/ansible-playbook-2/usr/bin/ansible-playbook-2.7/usr/bin/ansible-pull/usr/bin/ansible-pull-2/usr/bin/ansible-pull-2.7/usr/bin/ansible-vault/usr/bin/ansible-vault-2/usr/bin/ansible-vault- 2.72, Configuration file
The ansible configuration file is installed under / etc/ansible by default
[root@master01 ansible] # pwd/etc/ansible [root@master01 ansible] # lltotal 28Murray RWMurray-1 root root 19980 Sep 14 04:00 ansible.cfg-rw-r--r-- 1 root root 1016 Sep 14 04:00 hostsdrwxr-xr-x 2 root root 4096 Sep 14 04:00 roles2.1, hosts configuration file parsing
The hosts file is the host template file that we operated with ansible.
# you can configure domain name or host IP address green.example.comblue.example.com192.168.100.1192.168.100.10# as shown in the following module, or you can set grouping to specify the operation group when using ansible. [webservers] alpha.example.orgbeta.example.org192.168.1.100192.168.1.110# can also be configured as follows if multiple hosts follow a naming convention. Www [001virtual 006] .example.com2.2, configuration ansible.cfg file
Because we do not configure ssh secret-free authentication, we need to modify the ansible.cfg file.
[root@master01 ansible] # vi / etc/ansible/ansible.cfghost_key_checking = False2.3, configuration hosts file
If ssh secret-free authentication has not been configured between hosts, you need to configure the user name and password in the configuration file.
[master] 172.31.194.114 ansible_ssh_user='root' ansibleslides passages miao123 passages 172.31.194.115 ansible_ssh_user='root' ansibleslides passages miao123 passages 172.31.194.116 ansible_ssh_user='root' ansibleslides passages miao123'[node] 172.31.194.117 ansible_ssh_user='root' ansibleslides passages miao123i' Third, ansible uses syntax
Only some important ansible syntax and parameters are listed here.
[root@master01 ansible] # ansible-- helpUsage: ansible [options] # We can see that the host template file needs to be specified after the ansible command, but not the default hosts file. Options:-C,-- check # use-C or-- check to run once without performing any changes (check syntax errors and check target achievement status)-f FORKS,-- forks=FORKS # specify tasks that run several hosts at a time The default is 5-m MODULE_NAME,-- module-name=MODULE_NAME # executes module name-a MODULE_ARGS,-- args=MODULE_ARGS # uses-an or-args to specify the module parameter-h -- help # for help-- list-hosts # lists which hosts perform operations. 4. Connectivity debugging 4.1. check the hosts file configuration first through-- list-host to see if the configuration is incorrect. # list all hosts [root@master01 ansible] # ansible all-- list-host hosts (4): 172.31.194.117 172.31.194.114 172.31.194.115 172.31.194.115 172.31.194.1 "list all master hosts [root@master01 ansible] # ansible master-- list-host hosts (3): 172.31.194.114 172.31.194.115 172.31.194.1" list all node Host [root@master01 ansible] # ansible node-- list-host hosts (1): 172.31.194.1174.2, Ping module tests host connectivity
When using the ping module, you no longer need to specify the-a parameter.
# use ping module to test connectivity of all hosts [root@master01 ansible] # ansible all-m ping/usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.25.3) or chardet (2.2.1) doesn't match a supported version! RequestsDependencyWarning) 172.31.194.114 | SUCCESS = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": false, "ping": "pong" # We see that this line ping returns pong, indicating that the host is ready to connect. } 172.31.194.116 | SUCCESS = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": false, "ping": "pong"} 172.31.194.117 | SUCCESS = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": false "ping": "pong"} 172.31.194.115 | SUCCESS = > {"ansible_facts": {"discovered_interpreter_python": "/ usr/bin/python"}, "changed": false, "ping": "pong"}