我正在尝试查询
ORACLE_HOME
环境变量,该变量是通过事实收集收集的。
我尝试按如下方式访问它:
- name: Print oracle_home env
debug:
msg: "{{ lookup('ansible.builtin.env','ORACLE_HOME') }}"
但是除了空字符串之外我没有得到任何结果。
但是,如果我查询整个
ansible_env
变量,则指定 ORACLE_HOME
:
- name: Print ansible_env
debug:
msg: "{{ ansible_env }}"
"msg": {
"BASH_FUNC_mc%%": "() { . /usr/share/mc/mc-wrapper.sh\n}",
"COLORTERM": "1",
"CPU": "x86_64",
"CSHEDIT": "emacs",
"CVS_RSH": "ssh",
"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/0/bus",
"FROM_HEADER": "",
"GPG_TTY": "/dev/pts/0",
"G_BROKEN_FILENAMES": "1",
"HISTSIZE": "1000",
"HOME": "/root",
"HOST": "XYZ",
"HOSTNAME": "XYZ",
"HOSTTYPE": "x86_64",
"LANG": "POSIX",
"LC_CTYPE": "en_US.UTF-8",
"LESS": "-M -I -R",
"LESSCLOSE": "lessclose.sh %s %s",
"LESSKEY": "/etc/lesskey.bin",
"LESSOPEN": "lessopen.sh %s",
"LESS_ADVANCED_PREPROCESSOR": "no",
"LIBGL_DEBUG": "quiet",
"LOGNAME": "root",
"MACHTYPE": "x86_64-suse-linux",
"MAIL": "/var/spool/mail/root",
"MANPATH": "/usr/share/man:/usr/local/man",
"MINICOM": "-c on",
"MORE": "-sl",
"ORACLE_BASE": "/u01/app/oracle",
"ORACLE_HOME": "/u01/app/oracle/product/18c/xe",
"ORACLE_SID": "XE",
"OSTYPE": "linux",
"PAGER": "less",
"PATH": "/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin",
"PROFILEREAD": "true",
"PWD": "/root",
"PYTHONSTARTUP": "/etc/pythonstart",
"QT_SYSTEM_DIR": "/usr/share/desktop-data",
"SHELL": "/bin/bash",
"SHLVL": "2",
"SSH_TTY": "/dev/pts/0",
"TERM": "xterm",
"USER": "root",
"WINDOWMANAGER": "/usr/bin/icewm-session",
"XCURSOR_THEME": "DMZ",
"XDG_CONFIG_DIRS": "/etc/xdg",
"XDG_DATA_DIRS": "/usr/share",
"XDG_RUNTIME_DIR": "/run/user/0",
"XDG_SESSION_CLASS": "user",
"XDG_SESSION_ID": "21",
"XDG_SESSION_TYPE": "tty",
"XKEYSYMDB": "/usr/X11R6/lib/X11/XKeysymDB",
"XNLSPATH": "/usr/X11R6/lib/X11/nls",
"_": "/usr/bin/python3.6"
有人可以帮助我吗?我做错了什么?
lookup() 在 Ansible 控制器上进行评估,可能不是您在用例中需要的。
- name: Print local oracle_home env
debug:
msg: "{{ lookup('ansible.builtin.env','ORACLE_HOME') }}"
如果您需要目标计算机上的 ORACLE_HOME,您可以更好地使用它:
- name: Print remote oracle_home env
debug:
msg: "{{ ansible_env.ORACLE_HOME }}"
注意:您的剧本需要
gather_facts: true
或 ansible.builtin.setup:
才能让 ansible_facts 填充环境变量。