You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rundeck无法识别/etc/ansible/hosts中的主机问题求助

Rundeck无法识别Ansible默认hosts文件主机的排查方案

问题背景

在安装Ansible的主机上,终端可正常执行ansible ping及运行playbook,但Rundeck无法读取/etc/ansible/hosts中的主机。以下是当前配置:

项目配置

project.ansible-config-file-path=/etc/ansible/ansible.cfg
project.ansible-executable=/bin/bash
project.ansible-generate-inventory=true
project.ansible-ssh-passphrase-option=option.password
project.ansible-windows-executable=powershell.exe
project.disable.executions=false
project.disable.schedule=false
project.execution.history.cleanup.batch=500
project.execution.history.cleanup.enabled=false
project.execution.history.cleanup.retention.days=60
project.execution.history.cleanup.retention.minimum=50
project.execution.history.cleanup.schedule=0 0 0 1/1 * ? *
project.jobs.gui.groupExpandLevel=1
project.later.executions.disable.value=0
project.later.executions.disable=false
project.later.executions.enable.value=
project.later.executions.enable=false
project.later.schedule.disable.value=
project.later.schedule.disable=false
project.later.schedule.enable.value=
project.later.schedule.enable=false
project.name=Ansible-Test
project.nodeCache.enabled=true
project.nodeCache.firstLoadSynch=true
project.output.allowUnsanitized=false
project.ssh-authentication=privateKey
project.ssh-keypath=/var/lib/rundeck/.ssh/id_rsa
resources.source.1.config.ansible-config-file-path=/etc/ansible/ansible.cfg
resources.source.1.config.ansible-gather-facts=true
resources.source.1.config.ansible-ignore-errors=true
resources.source.1.config.ansible-inventory=/etc/ansible/hosts
resources.source.1.type=com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory
service.FileCopier.default.provider=jsch-scp
service.NodeExecutor.default.provider=com.batix.rundeck.plugins.AnsibleNodeExecutor

Ansible配置文件(ansible.cfg)

[defaults]
inventory      = /etc/ansible/hosts

排查步骤

  • 修正Ansible可执行路径配置
    当前project.ansible-executable设为/bin/bash是错误的,需改为实际Ansible可执行文件路径,可通过终端执行which ansible获取正确路径,示例配置:

    project.ansible-executable=/usr/bin/ansible
    
  • 禁用Rundeck自动生成inventory
    配置中project.ansible-generate-inventory=true会让Rundeck自动生成inventory文件,覆盖自定义的hosts路径,需改为:

    project.ansible-generate-inventory=false
    
  • 检查文件访问权限
    确保Rundeck运行用户(默认是rundeck)能读取/etc/ansible/hosts和/etc/ansible/ansible.cfg:

    1. 执行命令检查权限:
      ls -l /etc/ansible/hosts
      ls -l /etc/ansible/ansible.cfg
      
    2. 切换到rundeck用户测试读取:
      su - rundeck -c "cat /etc/ansible/hosts"
      

    若读取失败,调整文件权限:

    chmod o+r /etc/ansible/hosts
    chmod o+r /etc/ansible/ansible.cfg
    
  • 验证Ansible在Rundeck用户环境下的可用性
    切换到rundeck用户,执行以下命令确认能正常解析inventory:

    su - rundeck -c "ansible-inventory --list"
    

    若输出包含hosts列表,说明Ansible环境正常;若报错,需排查rundeck用户的Ansible环境变量或配置。

  • 手动刷新节点缓存
    在Rundeck界面进入项目的「节点」页面,点击「刷新节点缓存」,等待缓存更新后查看节点列表。

  • 检查插件兼容性
    确认使用的com.batix.rundeck.plugins.AnsibleResourceModelSourceFactory插件版本与当前Rundeck、Ansible版本兼容,必要时更新插件。

内容的提问来源于stack exchange,提问作者cnrdvdsmt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 15:30:00