尽管在 Ansible 中提升了权限,但仍无法运行脚本

Unable to run script despite escalating privilege in Ansible(尽管在 Ansible 中提升了权限,但仍无法运行脚本)
本文介绍了尽管在 Ansible 中提升了权限,但仍无法运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我尝试在使用 ansible 将它复制到主机上后在主机上运行它.该脚本有 777 个权限.

Im trying to run a shell script on the host machine after copying it over there using ansible. The script has 777 permissions.

请阅读以下问题,因为它提供了我们正在尝试处理的实际问题的完整范围

Please read the below question as it gives the full scope of the actual issue that we are trying to deal with

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

- name: Run the Script [List]
  shell: "/tmp/sqlscript/sql_select.sh {{item}} >> /tmp/sqlscript/output.out"
  become: yes
  become_method: sudo
  become_user: oracle
  register: orh
  with_items: "{{ factor_dbs.split('\n') }}"

下面是shell脚本

#!/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

尽管提升了权限,但我观察到除非我添加如下环境变量,否则任务不会执行

Despite escalating the privileges, I observed that the task is not executing unless I add environment variables like below

- name: Run the script [List]
  shell: "/tmp/sqlscript/oracle_home.sh {{item}} >> /tmp/sqlscript/orahome.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"
  register: orh
  with_items: "{{ factor_dbs.split('\n') }}"

然而,这个剧本需要在具有不同路径和 oracle_home 变量的不同主机上运行.

However this playbook needs to be run across different hosts which have different path and oracle_home variables.

我的问题是,为什么尽管升级了权限,任务仍然运行.当我尝试通过登录服务器并在执行sudo su oracle"后手动运行相同的脚本时,它似乎运行良好.

My question is, why doest the task run despite escalating the permissions. When I try to run the same script manually by logging into the server and after doing "sudo su oracle", it seems to be running fine.

推荐答案

这取决于您实际设置环境变量的位置.在远程机器上登录时执行脚本与通过 ssh 像 Ansible 一样运行脚本是有区别的(参见例如 区分交互式登录和非交互式非登录外壳).根据 shell 的类型和您的系统,加载不同的 bash 配置文件.

It depends on where you actually set your environment variables. There is a difference in executing a script when you are logged in at a remote machine, and running a script over ssh as Ansible does (see e.g., Differentiate Interactive login and non-interactive non-login shell). Depending on the type of shell and your system, different bash profiles are loaded.

这篇关于尽管在 Ansible 中提升了权限,但仍无法运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

相关文档推荐

Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
Creating a flattened table/view of a hierarchically-defined set of data(创建分层定义的数据集的扁平表/视图)
MySQL: how to do row-level security (like Oracle#39;s Virtual Private Database)?(MySQL:如何做到行级安全(如 Oracle 的 Virtual Private Database)?)
What is the best way to enforce a #39;subset#39; relationship with integrity constraints(强制执行具有完整性约束的“子集关系的最佳方法是什么)
Split String by delimiter position using oracle SQL(使用 oracle SQL 按分隔符位置拆分字符串)
How to unfold the results of an Oracle query based on the value of a column(如何根据列的值展开Oracle查询的结果)