ansible - 如何使用listen_ports_facts模块,ansible
问题描述
使用ansible我想检查tomcat在哪个端口运行,当然我认为有不同的方法可以做到,但是我找到了这个ansible模块
https://docs.ansible.com/ansible/latest/modules/listen_ports_facts_module.html
我想用它,但是根据例子,我不知道如何使用它。
我的意思是如果我设置
gather_facts: true
并运行任务
- name: List TCP ports
debug:
msg: "{{ ansible_facts.tcp_listen }}"
我得到了错误
TASK [discover-servers : List TCP ports] *******************************************************************************************************************************
task path: /home/A78252689/sap_bo/roles/discover-servers/tasks/tomcat_servers.yml:4
fatal: [2a00:da9:2:21ca:111:0:426:2]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'tcp_listen'\n\nThe error appears to be in '/home/A78252689/sap_bo/roles/discover-servers/tasks/tomcat_servers.yml': line 4, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: List TCP ports\n ^ here\n"}
如果我在示例中完全按照它的方式设置任务,我在第一个任务中出现错误收集关于侦听端口的事实
TASK [discover-servers : include_tasks] ********************************************************************************************************************************
task path: /home/A78252689/sap_bo/roles/discover-servers/tasks/main.yml:4
fatal: [2a00:da9:2:21ca:111:0:426:2]: FAILED! => {"reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path.\n\nThe error appears to be in '/home/A78252689/sap_bo/roles/discover-servers/tasks/tomcat_servers.yml': line 4, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gather facts on listening ports\n ^ here\n"}
那么,您知道如何使用模块 listen_ports_facts 吗?提前感谢您的支持
解决方案
您的gather_facts
剧本运行阶段使用该setup
模块。它不运行listen_ports_facts
,因此如果您不明确运行该模块,您将无法获得这些事实。
从文档中,listen_ports_module
创建了以下事实:
tcp_listen
udp_listen
使用 Ansible 2.9.2,以下工作正常:
---
- gather_facts: false
hosts: localhost
tasks:
- listen_ports_facts:
- debug:
msg: "{{ tcp_listen }}"
- debug:
msg: "{{ udp_listen }}"
如果您尝试运行该listen_ports_facts
模块并且收到错误“在任务中未检测到任何操作”,则可能是您正在运行没有该listen_ports_facts
模块的旧版 Ansible。它首先出现在 2.9 版本中。
推荐阅读
- javascript - React Native 应用程序已安装但在主屏幕或应用程序屏幕上不可见
- firebase - Bigquery 新架构——Firebase 中的会话持续时间分布表
- python - 在 numpy/scipy 中求解 3D 最小二乘
- ionic-framework - 通过 AlertController 在警报提示中的 Ionic3 中的复选框
- java - CellType 上的 Apache POI 4.0.0 编译错误
- sql - 如何获取不包含在 group by (SQL Server) 中的列的值
- reactjs - 如何在 react js 中使用来自 firebase 的 uuid?
- java - String.getBytes() 如何将字符串转换为字节?
- python - 如何在 python 中使用 gTTS?
- java - 如何计算java中任何一个月的工作日数?