Automated Batch Deployment Tool Ansible notes Ansible installation and inventory files
I. Introduction of Ansible
Ansible is an automated operation and maintenance Deployment tool, and Saltstack,pupet, and so on, Ansible does not adopt the C/s architecture, that is, there is no client and server points. This means that the installation of ansible is more convenient and the management node is more flexible (any machine with ansible installed can act as a management node).
Ansible provides a rich module for easy management tasks, and for complex administrative tasks, Ansible is executed in batches by writing playbook. Ansible can also perform operations concurrently, and can perform various tasks in playbook simultaneously on multiple machines.
By the way, Ansible is based on the SSH protocol.
Ii. ansible Installation and deployment
You can visit Ansible's github to find ansible source code, address: https://github.com/ansible/ansible
When you install ansible, you do not install a database or any daemons on your machine, you simply need to install ansible on a machine that can manage your console remotely, even a laptop.
Host requirements for the Ansible management node:
1, python2.6 or python2.7
2. Management node does not support Windows system
3. Applicable system including Red Hat,centos,debian,os X, and BSD series system
Ansible host requirements for managed nodes:
The managed node needs to install more than python2.4, but if the Python version is lower than python2.5, you will need to install the dependent package Python-simplejson (try Yum mode installation)
Attention:
1, ansible "raw" module and "script" module does not need Python-simplejson, so you can use these two modules to install this file;
2, if you open on the Remote management node SELinux, then before you use the "copy/file/template" function, to install the Libselinux-python package, you can use the Ansible Yum module to install the package;
3, Python2 is not installed by default. x instead of installing the python3.x system, you can install the python2.x version yourself, and then specify the path to the python2.6 you installed by setting the Ansible_python_interpreter environment variable.
To install ansible on the management node:
This article installs ansible on the CentOS 6.5 system via Yum and the Epel source is already installed on the machine, please refer to the official documentation for other system installation methods.
[Email protected] ~]# yum-y install ansible
Common configuration items in the ansible configuration file:
[defaults]inventory =/etc/ansible/hosts//Specify the Hosts file path, the file is logged in the managed node and its grouping sudo_user = root//Specify sudo user is Roo Ttimeout = 10//Specifies the time-out for SSH, which is appropriately changed to avoid errors caused by SSH timeouts
Three, ansible command common options
Ansible command format:
Ansible < host group > [Options] [-M module name] [-A parameter]
Common options are as follows: -v, --verbose verbose mode, output more successful task information-i path, --inventory=path specify the default inventory file path, default to/etc/ Ansible/hosts-f num, --forks=num number of concurrent numbers, where NUM should be set to an integer, the default is 5--private-key=private_key_ File sets the default SSH link certified files-m name, --module-name=name specify the module name-m directory, --module-path= directory specifies the path to find the module, and the default path is/usr/share/ansible. This function can also be implemented by setting the environment variable ansible_library to implement-a ' ARGUMENTS ', --args= ' ARGUMENTS ' parameters passed to the module-k, -- Ask-pass Prompt for SSH login password-k, --ask-sudo-pass prompt for sudo password-o, --one-line single-line output-s, -- sudo uses the-u option to specify the user execution command and sudo to the root user (there is a problem with the translation)-t directory, --tree=directory saves the output to the specified directory, The file is saved as a host address in this directory-t seconds, --timeout=seconds connection host timeout time-b num, --background=num run in the background, After the time that the option is set to kill the task-p num, --poll=num per NUM second to check for tasks running in the background, the-B option is required-u username, --user= USERNAME replaces the current user name with this remote user name-u sudo_username, --sudo-user=sudo_username SUDO from the root user to the user specified by this option-c Connection, --connection=connection connection types, optional types are Paramiko (SSH), SSH, andLocal Local is most commonly used in crontab and kickstarts-l subset, --limit=subset to further restrict the selected host/group mode-l ~regex, --limit=~ Regex uses regular expressions to further restrict the host--list-hosts list of all hosts that match, without performing any action
Iv.. Inventory file
Ansible through the inventory file to get the operation of the host, by default, the file is stored in the/etc/ansible/hosts. You can also use multiple inventory files at the same time, or get inventory files dynamically.
1. Hosts and host groups
Here is the content of a inventory file, with INI-style content:
[webserver]192.168.1.125192.168.1.126[dbserver]192.168.1.10www.example.com192.168.1.12:3300
where "[]" content is the group name, which is the IP or domain name of each host, the same host can be placed in different groups at the same time, then you can specify the port number.
When there are a host of similar host names, you can add them as follows, without adding a single bar:
[webserver]www[01:50].example.com
The above method can add 50 machines at a time. In addition to using the range of numbers, you can also use a letter range. Like what:
[dbserver]db-[a:f].example.com
You can specify the link type and the linked user for each host in the inventory file:
[Testserver]10.1.1.1ansible_connection=local10.1.1.2ansible_connection=sshansible_ssh_user=test
2. Host variables
In the inventory file, you can specify variables for each host, and variables can be used in playbook:
[testserver]host1http_port=80host2http_port=8088
3. Host group variables
If all hosts in a host group need to specify the same variables, the host group variable can be used, using the: VARs suffix to make the variable effective:
[testserver]host1host2[testserver:vars]ntp_server=ntp.example.comproxy=proxy.example.com
4. Group, and group variables for host groups
You can put a host group into another group by using the: children suffix to make a new group, or you can use a variable:
[testserver]host1host2[webserver]host2host3[group:children]testserverwebserver[group:vars]system_timeout=30
(Part of this article is translated from ansible official documents, if there is no place to translate!) )
This article is from the "Artisan" blog, please be sure to keep this source http://8838848.blog.51cto.com/8828848/1698106
Automated Batch Deployment Tool Ansible notes Ansible installation and inventory files