繁体   English   中英

在一本 Ansible 剧本中安装 Python 后如何收集事实?

[英]How to gather facts after installing Python in one Ansible playbook?

在执行我的剧本时,我需要收集事实。 但是主机还没有安装Python。

如果我先收集事实,剧本会因为缺少 Python 而引发错误。 如果我先安装 Python,我必须将gather_facts设置为no

在一本 Ansible 剧本中安装 Python 后如何收集事实?

这是我的剧本:

---
- hosts: all
  gather_facts: yes

  pre_tasks:
    - name: Install Python 2.x
      raw: test -e /usr/bin/python || (apt update && apt install -y python-simplejson)

  tasks:
    ...

使用setup模块。

---
- hosts: all
  gather_facts: no

  pre_tasks:
    - name: Install Python 2.x
      raw: test -e /usr/bin/python || (apt update && apt install -y python-simplejson)

  tasks:
  - name: Get facts
    setup:

  - name: Other tasks.....
  ....

文档: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM