First, host planning
Create 4 virtual machines as a demo ansible environment, install the operating system as CentOS 7.4. 1 of them as management host, the other 3 as the managed host. IP and host name are: IP host name note 192.168.128.10 Ansible-manager Management host 192.168.128.11 Ansible-demo1 managed host 1 192.168.128.12 Ansible-demo2 Managed Host 2 192.168.128.13 Ansible-demo3 managed host 32, installation Ansible
Use Yum to install ansible on the admin host. Because the installation ansible need Epel Source, this configuration has Ali's Yum source and Epel source.
cd/etc/yum.repos.d/
Yum Source
VI Centos-base.repo
[Base]
name=centos-$releasever-base
mirrorlist=http://mirrorlist.centos.org/?release= $releasever &arch=$ Basearch&repo=os&infra= $infra
#baseurl =http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7
#released updates
[updates]
name=centos-$releasever-updates
mirrorlist=http://mirrorlist.centos.org/?release= $releasever &arch = $basearch &repo=updates&infra= $infra
#baseurl =http://mirror.centos.org/centos/$releasever/updates/ $basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7
#additional Packages It is useful
[extras]
name=centos-$releasever-extras
mirrorlist=http://mirrorlist.centos.org /?release= $releasever &arch= $basearch &repo=extras&infra= $infra
#baseurl =http:// mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/ Rpm-gpg-key-centos-7
Epel Source
VI Epel.repo
[Epel]
Name=extra Packages for Enterprise Linux 7-$basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
Failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/rpm-gpg-key-epel-7
Install Ansible:
[Root@ansible-manager ~]# Yum Install ansible
Installation complete, view version:
[Root@ansible-manager ~]# ansible--version
ansible 2.5.1
config file =/etc/ansible/ansible.cfg
Configured module Search Path = [u '/root/.ansible/plugins/modules ', U '/usr/share/ansible/plugins/modules ']
Ansible Python Module location =/usr/lib/python2.7/site-packages/ansible
executable location =/usr/bin/ansible< C11/>python Version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
Third, ansible configuration file
Installation is complete, you can modify the default configuration, generally do not need to modify.
Vi/etc/ansible/ansible.cfg
[Defaults]
# some basic default values ...
#inventory = location of the/etc/ansible/hosts # List (inventory) file
#library =/usr/share/my_modules/ # storage Directory #module_utils of the ansible module =/usr/share/my_module_utils/
#remote_tmp = ~/.ansible/tmp # Temporary files remote Host storage directory
#local_tmp = ~/.ansible/tmp # Temporary files local directory
#plugin_filters_cfg =/etc/ansible/ Plugin_filters.yml
#forks = 5 # default concurrency number
#poll_interval = # Default Polling time interval
#sudo_user = root # default sudo user
#ask_sudo_pass = True # need sudo password
#ask_pass = True # Do you need a password
#transport = Smart
#remote_port = #指定连接被管理主机的管理端口, default is
#module_lang = C
#module_set_locale = False
...
Iv. Summary
This section describes how to install ansible and the meaning of ansible configuration parameters. In the next section, we start with a simple command to learn how to manage a host based on Ansible.
Reference Documentation:
http://www.ilurker.cn/?post=282
"Ansible Automation: Technology and best Practices"
"Ansible Authority Guide"