尽管Ansible中的权限升级,但仍无法运行脚本 [英] Unable to run script despite escalating privilege in Ansible

查看:102
本文介绍了尽管Ansible中的权限升级,但仍无法运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用ansible将shell脚本复制到主机上之后,在主机上运行shell脚本.该脚本具有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') }}"

但是,此剧本需要在具有不同path和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.

推荐答案

这取决于您实际设置环境变量的位置.当您在远程计算机上登录时执行脚本和通过Ansible在ssh上运行脚本是有区别的(请参见例如

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中的权限升级,但仍无法运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆