Linux 如何从Ansible剧本中检查环境变量?

Linux 如何从Ansible剧本中检查环境变量?,linux,ansible,environment-variables,Linux,Ansible,Environment Variables,我试图让Ansible角色在我的远程服务器上定义环境变量,但我的linter要求我使用“when:”语句来调节命令模块的任何使用 - name: Set environment variables in .profile file become: true template: src: .profile.j2 dest: "{{ env_home.value }}/.profile" owner: "{{ unix_user.name }}" group:

我试图让Ansible角色在我的远程服务器上定义环境变量,但我的linter要求我使用“when:”语句来调节命令模块的任何使用

- name: Set environment variables in .profile file
  become: true
  template:
    src: .profile.j2
    dest: "{{ env_home.value }}/.profile"
    owner: "{{ unix_user.name }}"
    group: "{{ unix_user.group }}"
    mode: 0777

- name: Load environment variables from .profile file
  become: true
  become_user: "{{ unix_user.name }}"
  command: "/bin/bash {{ env_home.value }}/.profile"

这段代码返回changed/ok,但我不知道环境变量是否在我的.profile模板中编写的
export{{{env_home.variable}}={{env_home.value}
之后定义得很好,我想添加一个任务,在加载.profile文件之前检查是否定义了所有环境变量所有环境变量都存储在事实
ansible\u env
中。因此,您可以在代码之后运行task
setup
再次收集新事实,然后检查
ansible_env

中的变量值,这不会给我ansible控制器上的环境变量而不是服务器的变量吗?不,
ansible_env
变量仅在从服务器收集事实时设置,这个变量对于每个服务器都是唯一的。