ansible暂停模块

pause

在playbook执行的过程当中暂停必定时间或者提示用户进行某些操做ssh

经常使用参数:ui

minutes:暂停多少分钟code

seconds:暂停多少秒对象

prompt:打印一串信息提示用户操做进程

示例:字符串

- name: wait on user input

   pause: prompt="Warning! Detected slight issue. ENTER to continue CTRL-C a to quit" 

- name: timed wait

  pause: seconds=30

复制代码
复制代码
wait_forinput

在playbook的执行过程当中,等待某些操做完成之后再进行后续操做cmd

经常使用参数:it

connect_timeout:在下一个任务执行以前等待链接的超时时间io

delay:等待一个端口或者文件或者链接到指定的状态时,默认超时时间为300秒,在这等待的300s的时间里,wait_for模块会一直轮询指定的对象是否到达指定的状态,delay即为多长时间轮询一次状态。

host:wait_for模块等待的主机的地址,默认为127.0.0.1

port:wait_for模块待待的主机的端口

path:文件路径,只有当这个文件存在时,下一任务才开始执行,即等待该文件建立完成

state:等待的状态,即等待的文件或端口或者链接状态达到指定的状态时,下一个任务开始执行。当等的对象为端口时,状态有started,stoped,即端口已经监听或者端口已经关闭;当等待的对象为文件时,状态有present或者started,absent,即文件已建立或者删除;当等待的对象为一个链接时,状态有drained,即链接已创建。默认为started

timeout:wait_for的等待的超时时间,默认为300秒

示例:

- wait_for: port=8080 state=started     #等待8080端口已正常监听,才开始下一个任务,直到超时

- wait_for: port=8000 delay=10    #等待8000端口正常监听,每隔10s检查一次,直至等待超时

- wait_for: host=0.0.0.0 port=8000 delay=10 state=drained    #等待8000端口直至有链接创建

- wait_for: host=0.0.0.0 port=8000 state=drained exclude_hosts=10.2.1.2,10.2.1.3    #等待8000端口有链接创建,若是链接来自10.2.1.2或者10.2.1.3,则忽略。

- wait_for: path=/tmp/foo    #等待/tmp/foo文件已建立

- wait_for: path=/tmp/foo search_regex=completed    #等待/tmp/foo文件已建立,并且该文件中须要包含completed字符串

- wait_for: path=/var/lock/file.lock state=absent    #等待/var/lock/file.lock被删除

- wait_for: path=/proc/3466/status state=absent        #等待指定的进程被销毁

- local_action: wait_for port=22 host="{{ ansible_ssh_host | default(inventory_hostname) }}" search_regex=OpenSSH delay=10    #等待openssh启动,10s检查一次

fail

用于终止当前playbook的执行,一般与条件语句组合使用,当知足条件时,终止当前play的运行。能够直接由failed_when取代。

选项只有一个:

msg:终止前打印出信息

示例:

- fail: msg="The system may not be provisioned according to the CMDB status."
  when: cmdb_status != "to-be-staged"
相关文章
相关标签/搜索