semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

How does environment variables supposed to work? It does not work for me.

Open whoisnobody opened this issue 2 years ago • 6 comments

I have a very simple use case scenario and I cannot make environments variables to be passed to my playbook. Vars are working correctly.

Environment config: obraz

Playbook:

- name: "Run"
  hosts: hosts
  roles:
    - run
  environment:
    ENV_TO_TEST: "changeit"
  vars:
    variable_to_test: "changeit"

variable_to_test is being replaced as expected with "test1" value. ENV_TO_TEST stays with value "changeit". It is not being replaced by the env defined in the semaphore.

Do I misunderstand something regarding environments functionality? Unfortunately I cannot find any info in docs about how does it work in deep.

whoisnobody avatar Jun 29 '23 07:06 whoisnobody

I don't believe you can change Environment variables via the command line in Ansible. Semaphore is essentially running a command line Ansible playbook.

Are you able to do what you want when running Ansible command line manually, outside of Semaphore? If so, copy that command here, maybe that will help in determining how to translate that into Semaphore...

jrglynn2 avatar Jun 29 '23 15:06 jrglynn2

Greetings.

From what I've read in the code the 'environment variables' are essentially set at the 'ansible-playbook' execution.

You could, per example, set Ansible configuration parameters using them (instead of using an 'ansible.cfg' file).

References:

Also: I am unsure if the 'environment.ENV_TO_TEST' would be replaced by Ansible. Have you verified that on a manual run?

ENV_TO_TEST=blub ansible-playbook test.yml

ansibleguy avatar Jul 22 '23 07:07 ansibleguy

For 'environment extra-vars' here would be the references:

NOTE: references do not exist any more

ansibleguy avatar Jul 22 '23 07:07 ansibleguy

I'm having similar issues to this where any variable that I place under "environment variables" does not load. When variables are placed in the "extra variables" section of environment or when it's defined in an inventory file, it does load.

When I run a playbook that relies on semaphore_slack_webhook, I get an error that that variable is not defined.

image

However, when I place the variable under extra variables as such:

image

Then my playbook does work.

Tried with several playbooks including debug tasks that just list all variables and it seems to me that any variables put under environment variables does not load.

TimoVerbrugghe avatar Sep 16 '23 15:09 TimoVerbrugghe

I'm having similar issues to this where any variable that I place under "environment variables" does not load. When variables are placed in the "extra variables" section of environment or when it's defined in an inventory file, it does load.

When I run a playbook that relies on semaphore_slack_webhook, I get an error that that variable is not defined.

+1 this. We cannot get this to work either for ANSIBLE_HOST_KEY_CHECKING. We tried every combination of variable, using extra vs environment and no success.

The only way I got it to work for me was to add

[defaults]
host_key_checking = False

In every inventory to turn it off. Its broken IMO unless we are missing something here.

kriegster108 avatar Dec 07 '23 00:12 kriegster108

I'm having similar issues to this where any variable that I place under "environment variables" does not load. When variables are placed in the "extra variables" section of environment or when it's defined in an inventory file, it does load. When I run a playbook that relies on semaphore_slack_webhook, I get an error that that variable is not defined.

+1 this. We cannot get this to work either for ANSIBLE_HOST_KEY_CHECKING. We tried every combination of variable, using extra vs environment and no success.

The only way I got it to work for me was to add

[defaults]
host_key_checking = False

In every inventory to turn it off. Its broken IMO unless we are missing something here.

I had the same issue. But when is set "ANSIBLE_HOST_KEY_CHECKING": false to lower characters "ansible_host_key_checking": false it works for me.

ramsnerm avatar Jun 07 '24 18:06 ramsnerm