使用 Terraform/OpenTofu 在 Rundeck 中配置 Ansible 作业

问题描述 投票:0回答:1

我已成功创建了一个 Terraform 文件,用于配置 Rundeck 来运行内联 BASH 脚本。然而,我想通过弄清楚如何自动配置使用 Ansible 的作业来更进一步。

通过阅读作业的提供者文档,看起来我需要在引用 Ansible 插件的

step_plugin
块中配置
command
。这需要一个
type
和一个
config
,如下所示:

不幸的是,与文档的其他部分不同,它没有列出

type
的可能值,所以我不得不猜测,到目前为止还没有成功。我总是收到类似以下内容的错误消息:

工作流程有一个或多个无效步骤:[1:[步骤插件类型“com.batix.rundeck.plugins.AnsiblePlaybookInlineWorkflowNodeStep”无效:找不到插件:com.batix.rundeck.plugins.AnsiblePlaybookInlineWorkflowNodeStep]]

我确实从

GET /plugins/list
端点查找了插件列表并尝试了这些名称,但它们不起作用:

我还在“ansible”、“playbook”和“inline”等词上尝试了很多camelCase、snake_case等变体,但似乎没有任何组合有效。我看到在返回的 API 输出中,它指出

builtin
设置为
false
。但是,如果我转到
artifact/index/configurations
,那么我可以看到“卸载”按钮,表明它们已安装。

问题

有人知道如何通过 Terraform/Tofu 在 Rundeck 中配置 Ansible 作业并可以提供一个基本示例吗?

ansible terraform rundeck opentofu
1个回答
0
投票

您必须添加指向插件名称和配置的

node_step_plugin
块(在
command
块内)。查看您需要哪些选项元素的一个好方法是创建一个模型 ansible 作业,以 YAML 格式导出它,然后查看要应用于 terraform
config
子块的作业定义内容。

terraform rundeck 部署文件如下所示(在 Terraform 1.8.0 和 Rundeck 5.2.0 上测试):

terraform {
  required_providers {
    rundeck = {
      source  = "rundeck/rundeck"
      version = "0.4.7"
    }
  }
}

provider "rundeck" {
  url         = "http://rundeck_url:4440/"
  api_version = "47"
  auth_token  = "rundeck_auth_token"
}

resource "rundeck_project" "terraform" {
  name        = "terraform"
  description = "Sample Created using Terraform Rundeck Provider"
  resource_model_source {
    type = "file"
    config = {
      format = "resourcexml"
      file = "/path/to/your/resources.xml"
      writable = "true"
      generateFileAutomatically = "true"
    }
  }
  extra_config = {
    "project.label" = "Ansible Example"
  }
}

resource "rundeck_job" "bounceweb" { 
  name              = "Ansible Test"
  project_name      = "${rundeck_project.terraform.name}"
  node_filter_query = "tags: ansible"
  description       = "Ansible Playbook Test"

  command {
    node_step_plugin {
      type = "com.batix.rundeck.plugins.AnsiblePlaybookWorflowNodeStep"
      config = {
        ansible-base-dir-path = "/path/to/ansible/config/"
        ansible-become = "false"
        ansible-binaries-dir-path = "/path/to/ansible/executable/"
        ansible-playbook = "/path/to/your/playbook/ping.yml"
        ansible-ssh-passphrase-option = "option.password"
        ansible-ssh-use-agent = "false"
      }
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.