Playbook被绞死了一段时间,然后恢复正常运行

时间:2019-08-05 11:55:01

标签: ansible

当我对包含很多任务的块使用WHEN条件时,剧本在进入该块并长时间处于挂起状态之前会卡住。

我在ansible.cfg中添加了ANSIBLE_SSH_PIPELINING = True,但是它不起作用。

- block:
    - block:
        - name: Interface Status Details
          include: interface_details.yml
          register: result

        - name: Interface Result Global
          set_fact:
            LowerCaseResult: "{{ result.stdout }}
        - debug: var=LowerCaseResult

    - block:
         - name: Calling Dependency Playbook
           include:  one_test.yml
           register: result

         - debug: var=result

      when: "'is up' in LowerCaseResult"

    - block:
         - name: Calling Dependency Playbook
           include:  two_test.yml
           register: cmd_result

         - debug: var= cmd_result
      when: "'is up' not in LowerCaseResult"
  when: true 

调试不打印,剧本卡住了很长时间,没有错误消息产生。

1 个答案:

答案 0 :(得分:0)

(可使用2.7.9)

ansible-lint 没有抱怨嵌套的 block (有趣!)请参见nested blocks lose conditions on parent blocks #12395(可在4月25日与协作者进行锁定和有限的对话)这可能引起问题,直到解决。


代码中的问题

1) include 使用 include_tasks

未注册任何内容
- name: Interface Status Details                                                 
  include_tasks: interface_details.yml                                           
  register: result                                                               

2)缺少引号;如果此结果中没有 stdout ,则任务将失败

- name: Interface Result Global
  set_fact:
    LowerCaseResult: "{{ result.stdout }}

正确,将默认设置为“未启用”

 - name: Interface Result Global
   set_fact:
     LowerCaseResult: "{{ result.stdout|default('is NOT up') }}"

3) var =

后的多余空间
- debug: var= cmd_result

正确

- debug: var=cmd_result

下面的播放可能正在起作用

- hosts: localhost
  tasks:
    - block:
        - block:
            - name: Interface Status Details
              include_tasks: interface_details.yml
              register: result
            - debug: var=result
            - name: Interface Result Global
              set_fact:
                LowerCaseResult: "{{ result.stdout|default('is NOT up') }}"
            - debug: var=LowerCaseResult

        - block:
            - name: Calling Dependency Playbook
              include_tasks:  one_test.yml
              register: result
            - debug: var=result
          when: "'is up' in LowerCaseResult"

        - block:
            - name: Calling Dependency Playbook
              include_tasks:  two_test.yml
              register: cmd_result
            - debug: var=cmd_result
          when: "'is up' not in LowerCaseResult"
      when: true