Ansible advantages over other automated operations tools (Saltstack, puppet):
Ansible is a lightweight framework that enables a variety of functions based on individual modules, which can be developed on demand
Agentless no need to install agent, according to the specific situation to establish a machine
Support Playbook Script
Python language development, do operations are more acceptable language
Other and so on, 100 degrees a large pile, self-Baidu Bar ~
Environment Description:
System Environment centos6.8
Operating Machine 192.168.1.121
Client 192.168.1.122
Basic Installation
Installing GCC for compiling Python source code
Yum Install GCC
Update Python version
CentOS comes with the python2.6 version, and since CentOS is already heavily dependent on Python, updating python2.7 is re-loading a
Download:
wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
Compile and install:
tar zxf python-2.7. A . TGZCD Python-2.7. A . /Configuremake doinstall
Modify the Python default version
MV /usr/bin/python/usr/bin/python2. 6 Ln -s/usr/local/bin/python2. 7 /usr/bin/python
To prevent Yum from performing exceptions, modify the Python version used by Yum
vi /usr/bin/yum
Modify the file header #!/usr/bin/python to #!/usr/bin/python2.6
Module installation
Setuptools
:
Https://pypi.python.org/pypi/setuptools
Compiling the installation
tar zxf setuptools-27.1. 2. Tar . GZCD setuptools-27.1. 2 Install
Errors that may occur when you install Setuptools
Runtimeerror:compression requires the (missing) zlib module
Workaround:
Installing zlib
Yum Install zlib zlib-devel-y
Enter the Python directory when the installation is complete
Recompile the installation python2.7
CD python-2.7. A Make Make Install
(Do not delete, directly compile the installation, the previously established soft chain is still valid)
Module installation
After the installation is complete, you can install most of the other modules with Easy_install.
Easy_install pycrypto pyyaml jinja2 markupsafe ECDSA Paramiko Simplejson
Problems that may occur when using Easy_install
Error:could not find suitable distribution for requirement.parse (' JINJA2 ')
I can't find the URL, etc information
Workaround:
Installing OpenSSL
Yum Install OpenSSL openssl-devel-y
Recompile installation after installation python2.7 (same as before)
Installing YAML
Download:
Http://pyyaml.org/download/libyaml/yaml-0.1.7.tar.gz
Compile and install:
tar zxf yaml-0.1. 7. Tar . GZCD Yaml-0.1. 7 . /Configuremake doinstall
Installing Ansible
Download:
Http://releases.ansible.com/ansible/ansible-2.1.1.0.tar.gz
TarInstall
or something simpler:
Install ansible
(both modes of installation will automatically select the appropriate latest version, the recommended Pip way, can automatically solve some dependency problems, but Pip installed no ansible.cfg and hosts)
Configure Ansible
SSH Password-free login
Ssh-keygen -t RSA
Return
Copy the ~/.ssh/id_rsa.pub to a different server and execute the following command on the other server
cat id_rsa.pub >>~/. ssh/authorized_keyschmod Authorized_keys
Ansible Configuration
mkdir -p/etc/ansible
Copy the Ansible.cfg and hosts files under Ansible/examples/to/etc/ansible/
Modify the Hosts file
Add the following content
[webserver] 192.168. 1.122
(That is, add 192.168.1.122 host under the Webserver group, you can add multiple hosts under the Webserver group, then you can operate directly on the webserver group)
Simple test
Ansible webserver-m command-a'uptime'
The appearance of green seccess words indicates success
Modules used by-m
-A parameter
Other modules
Ping
Setup
File
Copy
Command
Shell
Wait a minute
Can be tested and used as needed
More Module Reference: Ansible-doc-l
Automatic operation Koriyuki ansible--installation configuration