Ansible Notes-install and configure ansible
1. Install ansible
The centos installation ansible is as follows:
[root@ansible ~] # yum-y install epel-release [root@ansible ~] # yum-y install ansible [root@ansible ~] # ansible-- version # installed version 2.9ansible 2.9.22, ansible parameter completion function
Since version 2. 9 of ansible, it supports option completion of commands and relies on python's argcomplete plug-in.
1) install argcomplete: [root @ ansible ~] # yum-y install python-argcomplete# or any system can use the pip tool to install argcomplete, as follows: [root@ansible ~] # pip install argcomplete2) after installation, you also need to activate the plug-in [root@ansible ~] # bash-version # requires that the bash version is greater than or equal to '4.2'GNU bash Version 4.2.46 (2)-release (x86_64-redhat-linux-gnu) [root@ansible ~] # activate-global-python-argcomplete # Activation plug-in
If the bash version is less than 4.2, register the completion feature separately for each ansible command, as follows:
3) re-enter the bash environment to test whether [root@ansible ~] # bash [root@ansible ~] # ansible-- syntax-check # only need to enter ansible-- syn to complete 3. Configure host mutual trust
Ansible is based on ssh communication by default. In order to avoid interactive questioning in the process of configuring host mutual trust, you can use the ssh-keyscan tool to add host authentication information and the sshpass tool (sshpass is automatically installed when you install sshpass). The specific process is as follows:
1) generate a key pair on ansible [root@ansible ~] # ssh-keygen-t rsa-f ~ / .ssh/id_rsa-N''2) write the host information (host key) of each node to ansible's "~ / .ssh/known_hosts" file [root@ansible ~] # ssh-keyscan 192.168.20.3 > > ~ / .ssh/known_hosts 2 > / dev/null3) distribute the ssh public key on control_node to each node [root@ Ansible ~] # sshpass-p '123.com' ssh-copy-id root@192.168.20.3#-p: the user password of the specified node
After configuring the mutual trust between the hosts of ssh, you can experience ansible.
4. Ansible configuration file
Ansible supports four ways to specify configuration files, which are parsed from top to bottom:
1) ANSIBLE_CFG: the configuration file specified by the environment variable
2) ansible.cfg: ansible.cfg under the current directory
3) ~ / .ansible.cfg: ansible.cfg under the home directory
4) / etc/ansible/ansible.cfg: default global profile