Ansible@一个高效率的配置管理工具-Ansible configure management-翻译(四)
Ansible@一个高效的配置管理工具--Ansible configure management--翻译(四)
无书面许可请勿转载
由于第三章内容较长,我将分做几个部分来翻译。
Advanced Playbooks So far the playbooks that we have looked at are simple and just run a number of modules in order. Ansible allows much more control over the execution of your playbook. Using the following techniques, you should be able to perform even the most complex deployments. Running operations in parallel By default, Ansible will only fork up to five times, so it will only run an operation on five different machines at once. If you have a large number of machines, or you have lowered this maximum fork value, then you may want to launch things asynchronously. Ansible's method for doing this is to launch the task and then poll for it to complete. This allows Ansible to start the job across all the required machines while still using the maximum forks. To run an operation in parallel, use the async and poll keywords. The async keyword triggers Ansible to run the job in parallel, and its value will be the maximum time that Ansible will wait for the command to complete. The value of poll indicates to Ansible how often to poll to check if the command has been completed. If you wanted to run updatedb across an entire cluster of machines, it might look like the following code: - hosts: all tasks: - name: Install mlocate yum: name=mlocate state=installed - name: Run updatedb command: /usr/bin/updatedb async: 300 poll: 10 You will notice that when you run the previous example on more than five machines, the yum module acts differently to the command module. The yum module will run on the first five machines, then the next five, and so on. The command module, however, will run across all the machines and indicate the status once complete. If your command starts a daemon that eventually listens on a port, you can start it without polling so that Ansible does not check for it to complete. You can then carry on with other actions and check for completion later using the wait_for module. To configure Ansible to not wait for the job to complete, set the value of poll to 0 . Finally, if the task that you are running takes an extremely long time to run, you can tell Ansible to wait for the job as long as it takes. To do this, set the value of async to 0 . You will want to use Ansible's polling in the following situations: • You have a long-running task that may hit the timeout • You need to run an operation across a large number of machines • You have an operation for which you don't need to wait to complete There are also a few situations where you should not use async or poll : • If your job acquires locks that prevent other things from running • You job only takes a short time to run
高级Palybook
之前我们遇到的playbook都比较简单,只需要运行一些模块就可以了。但是Ansible可以在你运行playbook的时候有更多的控制,通过这些技术,你可以完成最最复杂的部署任务