Help with extra_vars format in awx_job_template
Closed this issue · 7 comments
Hi, I want to add extra_vars to a job template, but says it's a string but I don two how to formate the extra_vars variable.
Here is the code I tested:
resource "awx_job_template" "uptime-kuma-notification-add" {
name = "uptime-kuma-notification-add"
inventory = awx_inventory.uptime-kuma.id
verbosity = 0
job_type = "run"
playbook = "playbooks/config.yml"
extra_vars = jsonencode({
"role_action": "notification-add"
})
project = awx_project.uptime-kuma.id
scm_branch = ""
job_slice_count = 2
allow_simultaneous = true
}
And here is the error:
│ Error: Unable to create resource for JobTemplate on /api/v2/job_templates/
│
│ with awx_job_template.uptime-kuma-notification-add,
│ on project-uptime-kuma.tf line 25, in resource "awx_job_template" "uptime-kuma-notification-add":
│ 25: resource "awx_job_template" "uptime-kuma-notification-add" {
│
│ invalid status code: 400, on /api/v2/job_templates/ with {"extra_vars":["Not
│ a valid string."]}
Any help? Thanks!
@CygnusHyoga which version of AWX are you using?
Can you also share the full creation with the inventory and project?
Hi illijamt,
AWX version: AWX 23.5.0
resource "awx_project" "uptime-kuma" {
name = "uptime-kuma"
organization = awx_organization.kame.id
scm_url = "https://xxxr/kubernetes/uptime-kuma-ansible.git"
scm_type = "git"
scm_branch = "main"
scm_clean = false
credential = awx_credential.gitea.id
}
resource "awx_inventory" "uptime-kuma" {
name = "uptime-kuma"
organization = awx_organization.kame.id
}
resource "awx_inventory_source" "uptime-kuma" {
name = "uptime-kuma"
inventory = awx_inventory.uptime-kuma.id
source = "scm"
source_project = awx_project.uptime-kuma.id
source_path = "inventory/hosts"
}
resource "awx_job_template" "uptime-kuma-notification-add" {
name = "uptime-kuma-notification-add"
inventory = awx_inventory.uptime-kuma.id
verbosity = 0
job_type = "run"
playbook = "playbooks/config.yml"
extra_vars = jsonencode({
"role_action": "notification-add"
})
project = awx_project.uptime-kuma.id
scm_branch = ""
job_slice_count = 2
allow_simultaneous = true
}
@CygnusHyoga can you give it a try with the new provider?
It's working perfect! Now I can add extra_vars 👍
I have to define
verbosity = 0
in the resource "awx_inventory_source" because it' give me an error:
│ Error: Unable to create resource for InventorySource on /api/v2/inventory_sources/
│
│ with awx_inventory_source.uptime-kuma,
│ on project-uptime-kuma.tf line 17, in resource "awx_inventory_source" "uptime-kuma":
│ 17: resource "awx_inventory_source" "uptime-kuma" {
│
│ invalid status code: 400, on /api/v2/inventory_sources/ with
│ {"verbosity":["\"%!s(float64=1)\" is not a valid choice."]}
Thanks!!!! It's works!
can you send me the tf code that creates an error so I can fix that as well?
I found the issue, will fix that one as well.
I can confirm that with the new provider it's work fine without define verbosity awx_inventory_source!