【问题标题】:How to run an Ansible task with become and the same $PATH?如何使用 become 和相同的 $PATH 运行 Ansible 任务?
【发布时间】:2016-05-22 04:58:40
【问题描述】:

我想运行this task,但它失败了,因为它找不到bundle 二进制文件,因为与我一起运行它的用户在Ansible 中的$PATH 与我只是sudo su - deploy 时不同。

如果我以 root 身份 SSH 进入该框,然后运行 sudo su - deployecho 'whoami' $PATH 我得到 deploy /home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

但如果我使用与 ansible 任务的 shell: 部分相同的命令,我会得到 deploy /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

rbenv 部分是在 /etc/profile.d/rbenv.sh 中设置的,但如果我使用 Ansible 运行它,它不会以某种方式加载。

我发现了一个古怪的技巧,可以在我所有的 shell: 参数前面加上 source /etc/profile.d/rbenv.sh,但感觉很脏 :)

我该如何解决这个问题?

PS:我在我的 Fedora 23 上使用 Ansible 2.0.2.0,它与 Ubuntu 14.04 服务器通信。

【问题讨论】:

    标签: linux shell ubuntu ansible


    【解决方案1】:

    http://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/

    区别很简单,/etc/profile 只针对 交互式 shell 和 /etc/bashrc 为两者执行 交互式和非交互式外壳。实际上在 Ubuntu 中 /etc/profile 直接调用 /etc/bashrc。

    所以在 .bashrc 中包含您的 /etc/profile.d/rbenv.sh 或

    我发现了一个古怪的 hack 来为我所有的 shell 添加前缀:params with source /etc/profile.d/rbenv.sh

    【讨论】:

    • 我认为您在这里有所作为。我没有将其标记为成功的答案,因为它不起作用,但我认为它是一个交互式 vs.非交互式外壳。我将源 /etc/profile.d/rbenv.sh 放在 /home/deploy/.bashrc 和 /etc/bash.bashrc 中。虽然它似乎在我以交互模式运行时拾取它,但它在 Ansible 中被忽略了。如果我修复它,我会更多地解决这个问题并让你发布:) 谢谢!
    猜你喜欢
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多