Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use ExtractValue in Ansible Playbook? #2613

Open
lug-gh opened this issue Dec 5, 2024 · 1 comment
Open

How to use ExtractValue in Ansible Playbook? #2613

lug-gh opened this issue Dec 5, 2024 · 1 comment
Labels

Comments

@lug-gh
Copy link
Contributor

lug-gh commented Dec 5, 2024

Question

Hello, I have created an “integration” in the semaphore, which is configured as follows:

ExtractValue

  • values source: body
  • body data type: json
  • key: vmname
  • environment variable: vmname

matcher

  • type: body
  • method: equals
  • body data type: json
  • key: key
  • value: test

This triggers my ansible task “webhook test”.

If I trigger the webhook with the following command:
curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"key\": \"test\", \"vmname\": \"test\"}" https://semaphore.example.org/api/integrations/1234567890abcdef
then the ansible task starts, but the environment variable “vmname” is empty.

- name: webhook test
  hosts: localhost
  tasks:
    - name: debug
      debug:
        msg: "VM NAME: {{ lookup('env', 'vmname') }}"

only prints VM NAME:

Even if I display the entire env, I can't find my variable anywhere, only the env variables of the task itself.

- name: show all env
  hosts: localhost
  gather_facts: yes
  tasks:
    - name: show all env
      debug:
        var: ansible_facts.env

I use semaphore in docker, and have the following in my docker compose env:
SEMAPHORE_FORWARDED_ENV_VARS: '["vmname"]'
Unfortunately, this did not help either, the variable is still empty or not set.

Related to

Web-Backend (APIs), Ansible (task execution)

@lug-gh lug-gh added the question label Dec 5, 2024
@lug-gh
Copy link
Contributor Author

lug-gh commented Dec 12, 2024

Okay, I was thinking too complicated. The variable is not loaded as an environment variable, but directly as an ansible variable.

So simply {{ vmname }}, instead of {{ lookup('env', 'vmname') }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant