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

Allocator capacity conditional breaks on Ansible 2.9 #150

Open
m-a-leclercq opened this issue Apr 11, 2022 · 0 comments
Open

Allocator capacity conditional breaks on Ansible 2.9 #150

m-a-leclercq opened this issue Apr 11, 2022 · 0 comments

Comments

@m-a-leclercq
Copy link
Contributor

Related to #147

This syntax breaks on ansible 2.9. It works on ansible 2.10 (confirmed) and it seems it passed your tests on 2.8.

Minimal example to reproduce behavior :

--
- name: "test"
  hosts: localhost
  connection: local
  tasks:
    - name: Set empty capacity if not defined
      set_fact:
        capacity: "{{ capacity | default('') }}"
    - name: "debug"
      debug:
        msg: /home/elastic/elastic-cloud-enterprise.sh {{ '--capacity ' + capacity if capacity }}

Results on Fedora 35 with Ansible 2.10.15 (python3)

ansible-playbook test.yml 
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'

PLAY [add admin] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [Set empty capacity if not defined] ***************************************
ok: [localhost]

TASK [debug] *****************************************************************
ok: [localhost] => 
  msg: '/home/elastic/elastic-cloud-enterprise.sh '

CentOS 7.9 with ansible 2.9.27 (python 2.7.5)

ansible-playbook  test.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [add admin] *************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************
ok: [localhost]

TASK [Set empty capacity if not defined] *************************************************************************************
ok: [localhost]

TASK [debug] ***************************************************************************************************************
fatal: [localhost]: FAILED! =>
  msg: |-
    The task includes an option with an undefined variable. The error was: the inline if-expression on line 1 evaluated to false and no else section was defined.

    The error appears to be in '<my_secret_filepath>/test.yml': line 9, column 7, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

            capacity: "{{ capacity | default('') }}"
        - name: "debug"
          ^ here

I would suggest using jinja2 syntax to avoid any problems with Ansible 2.9 which I believe is the most widely used version at the moment.
I will create a PR once I check the correct jinja2 syntax.

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

No branches or pull requests

1 participant