python - 在一个 Ansible 剧本中安装 Python 后如何收集事实?
问题描述
在执行我的剧本时,我需要收集事实。但是主机还没有安装 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
推荐阅读
- c++ - 链接器如何找到正确的库?
- c# - 通过 Azure CDN 添加捆绑包、缩小和压缩
- python - 需要 MacOS 11 或更高版本!PyCharm 上的错误
- docker - 保存 Prometheus 指标
- sql - 查看 SQL 字段是否随着时间的推移将某些用户的 False 更改为 True 的最简单方法?
- java - 使用“try {} catch (Exception e) {}”时扫描仪不接受输入
- rust - 锈:是`盒子
` 真的类似于 `&'static T` 吗? - powershell - 将 .exe 应用程序安装到远程计算机 - Powershell
- c# - 更新 DataGridView 中每一行的更改
- sqlite - SQLite decimal(12,2) ,它实际上是如何工作的?