【发布时间】:2019-02-07 12:06:53
【问题描述】:
我在 ansible 中编写了一个剧本任务。我可以在 linux 端运行 playbook。
- name: Set paths for go
blockinfile:
path: $HOME/.profile
backup: yes
state: present
block: |
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export FABRIC_CFG_PATH=$HOME/.fabdep/config
- name: Load Env variables
shell: source $HOME/.profile
args:
executable: /bin/bash
register: source_result
become: yes
在 linux 中,我们在主目录中有 .profile,但在 Mac 中,在 macOS 中没有 .profile 和 .bash_profile。
所以我想检查 os 是否是 Mac,那么路径应该是 $HOME/.bash_profile,如果 os 是基于 linux 的,那么它应该寻找 $HOME/.profile。
我已经尝试添加
when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'precise'
但它首先不起作用,而且它是长度过程。我想在变量中获取基于 os 的路径并使用它。
谢谢
【问题讨论】: