我有一本安装 PythonBrew 的剧本。为此,我必须修改 shell 环境。因为 Ansible 中的 shell 步骤不是持久的,所以我必须在export PYTHONBREW_ROOT=${pythonbrew.root}; source ${pythonbrew.root}/etc/bashrc;
每个 PythonBrew 相关命令的开头添加:
- name: Install python binary
shell: export PYTHONBREW_ROOT=${pythonbrew.root}; source ${pythonbrew.root}/etc/bashrc; pythonbrew install ${python.version}
executable=/bin/bash
- name: Switch to python version
shell: export PYTHONBREW_ROOT=${pythonbrew.root}; source ${pythonbrew.root}/etc/bashrc; pythonbrew switch ${python.version}
executable=/bin/bash
我想消除这种冗余。在Ansible 讨论组中,我被提到了environment
关键字。我查看了文档中的示例,但对我来说并没有点击。对我来说, environment 关键字看起来与任何其他变量都没有太大不同。
我一直在寻找其他示例,但只能找到这个非常简单的示例。
有人可以演示environment
关键字在 Ansible 中的作用,最好使用我上面提供的代码示例吗?