semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform, OpenTofu, PowerShell and other DevOps tools.
https://semaphoreui.com
MIT License
10.69k stars 1.07k forks source link

Question: How to define host specific variables? #2423

Open Fernien opened 1 month ago

Fernien commented 1 month ago

Question

Hey,

I'm running an ansible playbook via the semaphoreui. My variables are defined in the "Environment Variables" section. My problem is that i need to overwrite some of the variables for specific hosts. I tried setting the variable via the inventory.

My inventory looks like this:

[docker-hosts]
docker01.example.com ACME_PROVIDER="autodns"

but the variable gets ignored/overwritten by Environment Variables tab. Haven't found a different way yet. How can i set host specific variables?

Grateful for every tip you can give me.

Related to

Ansible (task execution), Configuration

EHEX-schildt commented 1 month ago

in Plain Ansible i would use host_vars & group_vars see also https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html

Semaphore load them from your Repository.

If you need to set them via Semaphore Environment (aka --extra-vars): Lets say you have a variable foo with default bar. on Server2 you want foo with value baz:

Inventory(ini):

Server1
Server2

Semaphore Environment (json):

{
  "host_specific_foo": {
    "Server2": "baz"
  },
  "foo": "{{ host_specific_foo[inventory_hostname] | default('bar', true) }}"
}