首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何显示使用with_items的任务的输出?

如何显示使用with_items的任务的输出?
EN

Stack Overflow用户
提问于 2019-02-22 03:53:16
回答 1查看 345关注 0票数 0

希望我的问题能有一个简单的解决方案

我正在尝试在一个节点上跨多个Oracle数据库运行SQL。我从ps -ef生成一个数据库列表,并使用with_items传递dbname值。

我的问题是,如何显示运行select语句的每个数据库的输出?

代码语言:javascript
复制
 tasks:

 

    - name: Exa check | find db instances

      become: yes

      become_user: oracle

      shell: |

         ps -ef|grep pmon|grep -v grep|grep -v ASM|awk '{ print $8 }'|cut -d '_' -f3

      register: instance_list_output

      changed_when: false

      run_once: true

 

    - shell: |

        export ORAENV_ASK=NO; export ORACLE_SID={{ item }}; export ORACLE_HOME=/u01/app/oracle/database/12.1.0.2/dbhome_1; source /usr/local/bin/oraenv; $ORACLE_HOME/bin/sqlplus -s \"/ as sysdba\"<< EOSQL

        select * from v\$instance;

         EOSQL

      with_items:

      - "{{ instance_list_output.stdout_lines }}"

      register: sqloutput

      run_once: true

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-22 06:19:47

下面的循环可能会起作用。

代码语言:javascript
复制
- debug:
    msg: "{{ item.stdout }}"
  loop: "{{ sqloutput.results }}"

如果没有,请查看变量的内容,并决定如何使用它。

代码语言:javascript
复制
- debug: var=sqloutput
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54815197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档