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

Workaround for missing shll enviroment variables? #951

Open YoSiJo opened 2 years ago

YoSiJo commented 2 years ago

I want to use the nb_inventory_inventory and therefore need to pass in the API endpoint and token as "shell enviroments". What currently probably does not work with semaphore.

AWX/TOWER has the same problem and the following solution:

# For use in Ansible Tower (AWX), please see this blog from RedHat: https://www.ansible.com/blog/using-an-inventory-plugin-from-a-collection-in-ansible-tower
# The credential for NetBox will need to expose NETBOX_API and NETBOX_TOKEN as environment variables.
# Example Ansible Tower credential Input Configuration:

fields:
  - id: NETBOX_API
    type: string
    label: NetBox Host URL
  - id: NETBOX_TOKEN
    type: string
    label: NetBox API Token
    secret: true
required:
  - NETBOX_API
  - NETBOX_TOKEN

# Example Ansible Tower credential Injector Configuration:

env:
  NETBOX_API: '{{ NETBOX_API }}'
  NETBOX_TOKEN: '{{ NETBOX_TOKEN }}'

I couldn't find a suitable equivalent for this on your end.

Any idea or solution?

dpskvn commented 2 years ago

You could pass the ENV variable through the Semaphore unit file, although that's problematic, especially if you have several inventories that need different keys (which is the case that I have).

To be honest, we keep recommending Semaphore to our clients as a lightweight Ansible GUI and almost every time we have to abandon it because it lacks the support for environment variables.

I'm currently considering re-adding this functionality: https://github.com/ansible-semaphore/semaphore/pull/458 but am not sure whether it would get merged.