gpt4 book ai didi

ansible - .zshrc 没有在 Ansible 中加载?

转载 作者:行者123 更新时间:2023-12-04 02:20:26 25 4
gpt4 key购买 nike

我正在试验是否可以检查 bundle 的版本在本地主机中使用 ansible-playbook local.ymllocal.yml所示以下。

  • 本地.yml
    ---

    - hosts: local
    remote_user: someuser
    tasks:
    - name: Check bundle version
    shell: "{{ansible_user_shell}} -l -c 'bundle --version'"
    args:
    chdir: "/path/to/rails/dir"

  • 库存文件如下:
  • 主机
    [local]
    127.0.0.1
    [local:vars]
    ansible_ssh_user=someuser

  • 但是我收到错误消息,

    stderr: zsh:1: command not found: bundle`



    我不知道为什么会收到此错误,因为我确认捆绑软件已安装在本地主机上。我还发现 shell 模块不使用登录 shell,所以 .zshrc 中的环境变量没有加载,所以我用 -l 运行 zsh (使用登录外壳)选项。但它不起作用。有什么我想念的吗?

    最佳答案

    我自己解决了这个问题。问题是zsh的配置。我认为 .zshrc 在每次登录时都会执行。这是不准确的,因为 .zshrc 仅在登录和 时加载。互动 贝壳。在上述情况下,命令为 不是 在交互式 shell 上运行,因此未加载 .zshrc。
    为了在每次使用登录 shell 时加载 .zshrc,我创建了 .zprofile它在登录外壳上加载如下:

    # include .zshrc if it exists
    if [ -f "$HOME/.zshrc" ]; then
    . "$HOME/.zshrc"
    fi

    另一种解决方案可能是添加 -i(interactive shell) 选项:)

    关于ansible - .zshrc 没有在 Ansible 中加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32306653/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com