尽管Ansible中的权限升级,但仍无法运行脚本

编程入门 行业动态 更新时间:2024-10-25 07:29:52
本文介绍了尽管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上运行脚本是有区别的(请参见例如).根据外壳类型和系统的不同,将加载不同的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中的权限升级,但仍无法运行脚本

本文发布于:2023-11-16 18:11:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但仍   脚本   权限   Ansible

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!