使用 Ansible 设置不同的 ORACLE_HOME 和 PATH 环境变量

Set different ORACLE_HOME and PATH environment variable using Ansible(使用 Ansible 设置不同的 ORACLE_HOME 和 PATH 环境变量)
本文介绍了使用 Ansible 设置不同的 ORACLE_HOME 和 PATH 环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我目前正在查询多个数据库并捕获查询结果

Im currently querying multiple databases and capturing the results of the query

我这样做的方式是,我编写一个复制shell脚本的任务,如下所示

The way Im doing it is, Im writing a task which copies a shell script, something like below

#!/bin/bash
source $HOME/bin/gsd_xenv $1 &> /dev/null

sqlplus -s <<EOF
/ as sysdba
set heading off


select d.name||','||i.instance_name||','||i.host_name||';' from v\$database d,v\$instance i;

EOF

在剧本中,我写的任务如下:

In the playbook, Im writing the task as below:

- name: List Query [Host and DB]
  shell: "/tmp/sqlscript/sql_select.sh {{item}} >> /tmp/sqlscript/output.out"
  become: yes
  become_method: sudo
  become_user: oracle
  environment:
    PATH: "/home/oracle/bin:/usr/orasys/12.1.0.2r10/bin:/usr/bin:/bin:/usr/ucb:/sbin:/usr/sbin:/etc:/usr/local/bin:/oradata/epdmat/goldengate/config/sys"
    ORACLE_HOME: "/usr/orasys/12.1.0.2r10"
  with_items: "{{ factor_dbs.split('\n') }}"

但是我注意到不同的主机有不同的 ORACLE_HOME 和 PATHS.如何在剧本中定义这些变量,以便任务选择正确的 ORACLE_HOME 和 PATH 变量并成功执行任务

However I have noticed that the different hosts have different ORACLE_HOME and PATHS. How can I define those variables in the playbook, so that the task picks the right ORACLE_HOME and PATH variables and execute the task successfully

推荐答案

您可以为每个主机定义特定于主机的变量.您可以编写您的库存文件,如:

you can define host specific variables for each of the hosts. You can write your inventory file like:

[is_hosts]
greenhat ORACLE_HOME=/tmp
localhost ORACLE_HOME=/sbin

类似于 PATH 变量

similarly for the PATH variable

那么你的任务:

演示结果的示例剧本:

- hosts: is_hosts
  gather_facts: false
  vars:

  tasks:
    - name: task 1
      shell: "env | grep -e PATH -e ORACLE_HOME"
      environment:
        # PATH: "{{ hostvars[inventory_hostname]['PATH']}}"
        ORACLE_HOME: "{{ hostvars[inventory_hostname]['ORACLE_HOME'] }}"
      register: shell_output

    - name: print results
      debug:
        var: shell_output.stdout_lines

示例输出,您可以看到 ORACLE_HOME 变量确实发生了变化,并且按照主机的定义:

sample output, you can see ORACLE_HOME variable was indeed changed, and as defined per host:

TASK [print results] ************************************************************************************************************************************************************************************************
ok: [greenhat] => {
    "shell_output.stdout_lines": [
        "ORACLE_HOME=/tmp", 
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
    ]
}
ok: [localhost] => {
    "shell_output.stdout_lines": [
        "ORACLE_HOME=/sbin", 
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
    ]
}

这篇关于使用 Ansible 设置不同的 ORACLE_HOME 和 PATH 环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
SQL query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)