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

如何通过Terraform/OpenTofu在Rundeck中配置Ansible作业?求示例

使用Terraform/OpenTofu配置Rundeck Ansible作业的正确方法及示例

核心问题解决:获取正确的step_plugin type值

你遇到的"插件未找到"问题,核心是没有使用Rundeck内部注册的插件精确type值。官方文档未列出这些值,可通过以下两种可靠方式获取:

  1. 从作业导出YAML中提取

    • 在Rundeck UI中手动创建一个临时Ansible作业(比如添加Ansible Playbook步骤)
    • 进入作业编辑页面,点击右上角「导出」→ 选择YAML格式
    • 在导出的YAML文件中,找到plugin节点下的type字段,这就是Terraform中需要的step_plugin.type值。示例片段:
      plugin:
        type: com.batix.rundeck.plugins.AnsiblePlaybookWorkflowStep
        configuration:
          playbook_path: "/path/to/playbook.yml"
      
  2. 通过Rundeck API查询

    • 调用对应版本的Rundeck API(替换42为你的Rundeck API版本):
      curl -H "X-Rundeck-Auth-Token: YOUR_TOKEN" http://your-rundeck-url/api/42/plugin-types/workflow-step
      
    • 在返回的JSON结果中,筛选Ansible相关插件,取name字段值作为type值。

基础Terraform配置示例

以下是配置Ansible Playbook作业的最小示例,注意替换type值为你获取到的精确值,以及项目名、路径等参数:

resource "rundeck_job" "ansible_deploy_job" {
  name        = "Ansible: Deploy Production"
  project     = "production-project"
  description = "Runs production deploy playbook"

  command {
    step_plugin {
      type = "com.batix.rundeck.plugins.AnsiblePlaybookWorkflowStep"
      config = {
        playbook_path        = "/var/rundeck/playbooks/deploy.yml"
        inventory_file       = "/var/rundeck/inventories/prod.ini"
        extra_vars           = "version=1.2.3"
        ansible_ssh_user     = "rundeck"
        become_enabled       = "true"
        become_method        = "sudo"
        ansible_extra_args   = "-v"
      }
    }
  }
}

常见注意事项

  • 插件type值大小写、格式必须完全匹配,任何拼写错误都会触发"插件未找到"错误
  • 如果配置Ansible Ad-Hoc命令,对应的type值会不同(比如com.batix.rundeck.plugins.AnsibleAdHocWorkflowStep),同样需从导出的作业YAML中获取
  • 确保Rundeck服务器上的Ansible环境配置正确(比如ansible命令路径、SSH密钥等),否则即使作业配置正确也会执行失败

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 14:30:23