First, Ansible Basic installationInstall RPM using Yum with epel6,7 and more. However, you must install Python2.4 or a later version of Python.Add Source:Wget-o/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repoYum Install Ansible-ySecond, ansible configuration1. SSH face key login settings# #生成公钥/Private keySSH-KEYGEN-T RSASsh-copy-id-i ~/.ssh/
Ansible learning-simple learning notes 2, ansible-learning notes
Roles is used for hierarchical and structured organization playbook, and the encryption process in previous note 1 is used.
My directory svnrepos has two directories.
Ansible_test and test
Under the test directory:
The directory structure of an
templates to replace variables in template files and implement some simple logic files5 handlers and notity are used in conjunction, the action triggered by a specific condition, satisfies the condition to execute, otherwise does not execute6 tags tag specifies a task execution that selects some code in the run playbook. The ansible is idempotent, so it will automatically skip the unchanged parts, even though some code will be very long to
, handlers}/main. ymltouch/etc/ansible/roles/PHP/{defaults, vars, tasks, Meta, handlers}/main. yml
2. compile the httpd module: write a simple tasks/main. yml: * VI/etc/ansible/roles/httpd/tasks/main. yml-Name: Ensure Apache is at the late ST version Yum: PKG ={{ PKG} state = latest definition variable: can be defined in global variables, it can also be defined in the roles role variable, which is generall
Ansible module-lineinfile example, ansible-lineinfileLineinfile module details
The lineinfile module is similar to the sed tool in linux, but the articles on the Internet generally only have simple instances, and there are no examples of complicated points.
The following is a common example of the lineinfile Module I have summarized based on my actual operations.
Directory
More powerful than Ansible automated O M tools, automated and unified installation and deployment _ automated deployment of unifyDeploy1.0, ansible
New features:
Septem
In addition to pass (backup and update) and start (start Service), all automation is achieved.
Note: pass and start are set as service classes. Because of different services, automation cannot be achieved. Except for similar businesses, suc
/ansible.cfgAbove is a sample custom single hostTo customize a single group example, the characters in brackets are group names, and a host can belong to more than one masterYou can use Ansible-i/somefile to indicate the inventory host file pathcustomizing two groupsAnsible-doc commands to see the Help, Ansible-doc-l lists which modules ansible support,
Configuration and testingThe first step is to modify the host and group configuration, file location/etc/ansible/hosts, format ini, add two host IP, and define two IP to webservers group, update the content as follows:"/etc/ansible/hosts" [webservers] #组名 websevers## alpha.example.org## beta.example.org172.31.101.51 #主机1 172.31.101.52 #主机2Ping module to test the
Ansible notesHosts: remote hostUser: Users who are executing the task groupRemote_user: Same as usersudo: If set to Yes, the user performing the task group gets root permission when the task is performed.Sudo_user: If you set user to Tom,sudo as Yes,sudo_user for Jerry, then Tom gets the permissions of the Jerry user.Connection: How to connect to the remote host.# # #gather: Collecting Facts: FactsGather_facts: Unless you explicitly indicate that you
Command module:The 1:command module executes the command on the remote node:The command module is followed by the commands to be executed, and the arguments to the command are separated by spaces. The specified command executes on the selected node. The command is not executed through the shell, so environment variables such as $home and some operators (1 chdir switch to the specified directory before running the command.[Email protected] ansible]#
;#Ansible: TimeSync* * * * */5 */usr/sbin/ntpdate 172.16.0.1 >/dev/nullDelete Crontab[Email protected] ~]# ansible cce-m cron-a ' name= "TimeSync" state= "absent" '6. Use the Fetch module to pull the directory on the remote host to the local[Email protected] ~]# ansible cce-m fetch-a ' Src=/root/cce dest=/root/cce '7. Use the file module to manage files on the re
Use redis to accelerate ansible and redis to accelerate ansibleUse redis to accelerate ansible
We know that every time we use ansible, we need to collect system information. This step takes a lot of time. We can use redis to save the GATHERING time.1. ansible. cfg
[Defaults] gathering = smartfact_caching = redisfact_
Ansible (10) first exercise and ansible first exerciseSummary
We have learned apt, yum, zypper, copy, and other modules. You must be bored.The following is a practical example.Actual case:
Batch tomcat configuration
Only the knowledge of the above modules is enough for us to orchestrate a Playbook to configure a large number of physical/virtual servers.Actual scenarios
A company has applied for 1
execute, and handlers defines which calls
Processor
Is a simple example:
How can I run my defined scripts? Use the ansible-playbook command, for example, ansible-playbook/root/first. yml.
Variable:
Variable name: it may consist of letters, numbers, and underscores. It can only start with a letter.
Variable type: facts (built-in variable)
Custom variables: (1) pass through command lines, (2) pass through
-id command to replicate the Ansible public key into the node.Fourth step: Define a list of nodes for AnsibleFile/etc/ansible/hosts maintains a list of servers in Ansible.[Email protected] ~]# vi/etc/ansible/hosts[Test-servers]192.168.1.9192.168.1.10Save and exit the file.Fi
of ansible modules. Because it is written in python, you can also customize your own modules!
Module_args = ''# parameters, you know
Pattern = 'lvs-bj-* '# host matching
Forks = 10 # fork? Don't read it wrong. It's fork... Fork process!
If you don't have ansible, check out my steps ~ I can't connect to the testing virtual machine today, so I will temporarily run a configuration
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.