Ansible,自定义事实 - '变量未定义!:''ogg_fact_general'' 未定义

问题描述 投票:0回答:1

Ansible 自定义事实,在 /etc/ansible/facts.d 中定义。我可以手动获取它们的值,就像这样:

[root@lnx000 templates]# ansible lnx072  -m ansible.builtin.setup | grep ogg_fact
                "ogg_fact_general": {
                    "ogg_fact_bu_name": "UPTER",
                    "ogg_fact_environment_type": "VAR",
                    "ogg_fact_home": "/goldengate",
                    "ogg_fact_next_depl_iterator": "114",
                    "ogg_fact_service_manager_port": "9000",
                    "ogg_fact_version": "21c"

但是,我在传递“ogg_fact_version”作为剧本中的变量时遇到了麻烦。为了进行比较,我放入了一个测试“ansible_distribution”事实,当然这不是自定义的。这个在调试中表现得很好。但不是我所追求的,我自己定义的“ogg_fact_version”。

剧本:

---
- hosts: ogg_servers
  become: yes
  gather_facts: True
  tasks:

  - debug: var=ansible_distribution

  - debug: var=ogg_fact_version

  - name: Generate a GoldenGate Response File for the oggca Utility to Create a New Deployment | Add a GoldenGate Deployment
    template:
        src: /etc/ansible/templates/oggca.rsp.j2
        dest: /tmp/ogg_add_depl.rsp
        owner: oracle
        group: oinstall
        mode: '0775'

输出(参见“UNDEFINED”):

[root@lnx000 ansible]# ansible-playbook ./playbooks/depl.yml

PLAY [ogg_servers] *******************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************
ok: [lnx072]
ok: [lnx000]
ok: [lnx001]

TASK [debug] *************************************************************************************************************************************************************************************************
ok: [lnx000] => 
  ansible_distribution: OracleLinux
ok: [lnx001] => 
  ansible_distribution: OracleLinux
ok: [lnx072] => 
  ansible_distribution: OracleLinux

TASK [debug] *************************************************************************************************************************************************************************************************
ok: [lnx000] => 
  ogg_fact_version: VARIABLE IS NOT DEFINED!
ok: [lnx001] => 
  ogg_fact_version: VARIABLE IS NOT DEFINED!
ok: [lnx072] => 
  ogg_fact_version: VARIABLE IS NOT DEFINED!

TASK [Generate a GoldenGate Response File for the oggca Utility to Create a New Deployment | Add a GoldenGate Deployment] ************************************************************************************
ok: [lnx072]
ok: [lnx000]
ok: [lnx001]

PLAY RECAP ***************************************************************************************************************************************************************************************************
lnx000                     : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
lnx001                     : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
lnx072                     : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[root@lnx000 ansible]# 

我的长期目标是使用“ogg_fact_version”作为目标模板文件名称中的部分字符串。

目标:/tmp/ogg_add_depl_{{ ogg_fact_version }} {{ ogg_fact_environment_type }}.rsp

但首先,当然,我需要确保它可以作为变量传递给 Ansible,Ansible 不能使用“ogg_fact_version”,因为它没有定义为实际内置的“ansible_distribution”。

请帮助解决这两个问题。

谢谢

我希望在剧本中看到“ogg_fact_version”,就像这里显示的手动 ansible 运行一样:

ansible lnx072 -m ansible.builtin.setup | grep ogg_fact

ansible ansible-2.x ansible-facts ansible-template
1个回答
0
投票

我自己解决了:

---
- hosts: ogg_servers
  become: yes
  gather_facts: True
  tasks:

  - debug: var=ansible_distribution

  - name: print ansible_local
    debug: var=ansible_local

#  - name: print book title
#    debug: msg="The Oracle GoldenGate version on this server is {{ ansible_local.ogg.ogg_fact_version.ogg_fact_version }}"

  - name: Generate a GoldenGate Response File for the oggca Utility to Create a New Deployment | Add a GoldenGate Deployment
    template:
        src: /etc/ansible/templates/oggca.rsp.j2
        dest: /tmp/ogg_add_depl_{{ ansible_local.ogg.ogg_fact_general.ogg_fact_version }}.rsp
        owner: oracle
        group: oinstall
        mode: '0775'
© www.soinside.com 2019 - 2024. All rights reserved.