我看到我的ansible剧本从不返回提示,当我启用DEBUG模式时,我看到某些东西在循环运行

时间:2019-05-17 20:31:06

标签: ansible

我觉得我的代码中有不正确的地方,这导致ansible在永无止境的循环中运行它,并且不返回命令提示符。

我尝试启用调试模式“ export ANSIBLE_DEBUG = 1”,发现某些内容在不断循环中不断运行。

这是我的剧本代码:

- hosts: all
  gather_facts: false
  strategy: free
  tasks:
  - include_vars: roles/oracle/vars/install_vars.yaml
    vars:
     var_list:
        - script_name

  - set_fact:
      ORACLE_HOMES_DIR: "/u01/app/oracle/product"
      DB_HOME: "{{ ORACLE_HOMES_DIR }}/{{ ORACLE_VERSION }}/dbinst_1"

  - name: Copy script to host
    copy:
      src: "{{ playbook_dir }}/{{ script_name }}"
      dest: "/tmp/"
      owner: "{{ USER_ORACLE }}"
      group: "{{ GROUP_ORACLE }}"
      mode: 0755

  - name: Verify if the DB is open READ WRITE (or) not
    become_user: "{{ USER_ORACLE }}"
    environment:
      ORACLE_SID: "{{ sid }}"
      ORACLE_HOME: "{{ ORACLE_HOME }}"
    shell: "echo \"set pagesize 0\n select trim(open_mode) from v\\$database;\" | {{ORACLE_HOME}}/bin/sqlplus -S / as sysdba"
    with_items: "{{ hostvars[inventory_hostname]['sid_list'] }}"
    loop_control:
      loop_var: sid
    register: om

  - name: Get list of sid that are open in READ WRITE mode
    set_fact:
      sid_list: "{{ om.results | selectattr('sid','search','1$') | map (attribute='sid') | list }}"

  - name: Get the OPEN MODE output of the sid's from the list
    set_fact:
      om_out: "{{ om.results | selectattr('stdout') | map (attribute='stdout') | list }}"

  - name: execute sql script
    become_user: "{{ USER_ORACLE }}"
    environment:
      ORACLE_SID: "{{ item.0 }}"
      ORACLE_HOME: "{{ ORACLE_HOME }}"
    shell: "{{ ORACLE_HOME }}/bin/sqlplus / as sysdba @/tmp/{{ script_name }}"
    when: item.1 == 'READ WRITE'
    with_together:
      - "{{ sid_list }}"
      - "{{ om_out }}"

它应该返回提示,如果我在一台主机上运行它,我的剧本可以正常工作,但是如果我在多台主机上循环访问,则我看到此问题。

这是我使用“ export ANSIBLE_DEBUG = 1”启用调试时看到的循环运行的内容:

  2804 1558117774.30825:  ^ state is: HOST STATE: block=3, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
  2804 1558117774.30843 [lt2racdb2]: free host state: HOST STATE: block=3, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
  2804 1558117774.30865 [lt2racdb2]: free host task: TASK: meta (flush_handlers)
  2804 1558117774.30880 [lt2racdb2]: this host has work to do
  2804 1558117774.30897: lt2racdb2 is blocked, skipping for now
  2804 1558117774.31028: next free host: lt1racdb1
  2804 1558117774.31045: getting the next task for host lt1racdb1
  2804 1558117774.31064: done getting next task for host lt1racdb1
  2804 1558117774.31080:  ^ task is: None
  2804 1558117774.31097:  ^ state is: HOST STATE: block=5, task=0, rescue=0, always=0, run_state=ITERATING_COMPLETE, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
  2804 1558117774.31114 [lt1racdb1]: free host state: HOST STATE: block=5, task=0, rescue=0, always=0, run_state=ITERATING_COMPLETE, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
  2804 1558117774.31131 [lt1racdb1]: free host task: None
  2804 1558117774.31147: next free host: lt1racdb2
  2804 1558117774.31164: getting the next task for host lt1racdb2
  2804 1558117774.31182: done getting next task for host lt1racdb2
  2804 1558117774.31201:  ^ task is: TASK: meta (flush_handlers)
  2804 1558117774.31218:  ^ state is: HOST STATE: block=3, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
  2804 1558117774.31235 [lt1racdb2]: free host state: HOST STATE: block=3, task=1, rescue=0, always=0, run_state=ITERATING_TASKS, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
  2804 1558117774.31255 [lt1racdb2]: free host task: TASK: meta (flush_handlers)
  2804 1558117774.31271 [lt1racdb2]: this host has work to do
  2804 1558117774.31287: lt1racdb2 is blocked, skipping for now
  2804 1558117774.31303: next free host: lt2racdb1
  2804 1558117774.31319: getting the next task for host lt2racdb1
  2804 1558117774.31337: done getting next task for host lt2racdb1
  2804 1558117774.31354:  ^ task is: None
  2804 1558117774.31370:  ^ state is: HOST STATE: block=5, task=0, rescue=0, always=0, run_state=ITERATING_COMPLETE, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
  2804 1558117774.31389 [lt2racdb1]: free host state: HOST STATE: block=5, task=0, rescue=0, always=0, run_state=ITERATING_COMPLETE, fail_state=FAILED_NONE, pending_setup=False, tasks child state? (None), rescue child state? (None), always child state? (None), did rescue? False, did start at task? False
  2804 1558117774.31406 [lt2racdb1]: free host task: None
  2804 1558117774.31422: next free host: lt2racdb2
  2804 1558117774.31438: getting the next task for host lt2racdb2
  2804 1558117774.31457: done getting next task for host lt2racdb2

0 个答案:

没有答案