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

when: evaluation doesn't like variables containing "-" (dashes) #8849

Closed
danvaida opened this issue Sep 2, 2014 · 3 comments
Closed

when: evaluation doesn't like variables containing "-" (dashes) #8849

danvaida opened this issue Sep 2, 2014 · 3 comments

Comments

@danvaida
Copy link
Contributor

danvaida commented Sep 2, 2014

Issue Type:

Bug Report

Ansible Version:

ansible 1.8 (devel 9edf3a7) last updated 2014/08/13 09:45:46 (GMT +200)

Environment:

Host is FC19 and Target is Wheezy 7.5

Summary:

In a task, upon using the 'when' functionality, the evaluation of the condition doesn't work if a variable contains the dash char in its name.

Steps To Reproduce:
- name: do something
  lineinfile:  bla bla bla
  when: (phpfe is defined) or (php-be is defined) or (nginx is defined) 
Expected Results:

Task gets applied on host that has the variable php-be defined.

Actual Results:

This only works for hosts phpfe and nginx.
When I change php-be to php_be, it works like a charm.

@danfaizer
Copy link
Contributor

Hi,
Ansible playbooks are written in YAML format. As far as I know, dash '-' is a reserved character in YAML specification[1]. Therefore, I believe there is no other solution than renaming those variables and avoid using reserved characters.

[1] http://yaml.org/spec/current.html#id2439001

@danvaida
Copy link
Contributor Author

danvaida commented Sep 2, 2014

Right ;) 10x.

@danvaida danvaida closed this as completed Sep 2, 2014
@jimi-c
Copy link
Member

jimi-c commented Sep 2, 2014

Possible Misunderstanding

Hi!

Thanks very much for your submission to Ansible. We believe the ticket you have filed is being somewhat misunderstood, as one thing works a little differently than stated.

The problem you are experiencing is due to the fact that variable names cannot include dashes. Please see http://docs.ansible.com/playbooks_variables.html#what-makes-a-valid-variable-name for details on variable naming.

In the future, this might be a topic more well suited for the user list, which you can also post here if you'd like some more help with the above.

Thank you once again for this and your interest in Ansible!

lihiwish added a commit to lihiwish/redis-role that referenced this issue Feb 7, 2018
Pull request [1] introduce a bug when the accessing to
redis-confs.cluster-config-file was done incorrectly.

Since dashes are reserved characters,
the accessing should be done in the "dictionary" way

Submitting it as part of fix idealista#30

[1] idealista#31

[2] ansible/ansible#8849
lihiwish added a commit to lihiwish/redis-role that referenced this issue Feb 7, 2018
Pull request [1] introduce a bug when the accessing to
redis-confs.cluster-config-file was done incorrectly.

Since dashes are reserved characters,
the accessing should be done in the "dictionary" way

[1] idealista#31

[2] ansible/ansible#8849
3JIou-home added a commit to 3JIou-home/molecule that referenced this issue Nov 12, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants