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

Enable SSL in haproxy.cfg if patroni_restapi_certfile is defined #2

Merged
merged 2 commits into from
Nov 2, 2022

Conversation

danopt
Copy link
Member

@danopt danopt commented Oct 24, 2022

@danopt
Copy link
Member Author

danopt commented Oct 24, 2022

Tested with both configurations.

  • No SSL:
    haproxy-no-ssl
  • SSL:
    haproxy-ssl

Copy link
Member

@widhalmt widhalmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you checking for?

If you want add the string when patroni_restapi_certfile is set to true then use | bool. If you're checking if the variable is defined at all please use is defined.

@danopt
Copy link
Member Author

danopt commented Oct 25, 2022

@widhalmt Thx. I want to check if the variable is defined at all. Currently, the variable is defined with patroni_restapi_certfile: "" in the defaults/main.yml or does it mean undefined?

I guess I'll take a look at it.

@danopt
Copy link
Member Author

danopt commented Oct 27, 2022

Hi @widhalmt,

we need to check if the variable is defined, but assigned to an empty string "" (?) :-)

I'm used to using only if because of Python. Small example:

>>> no_ssl = ""
>>> if no_ssl:
...   print('pass')
... else:
...   print('fail')
... 
fail
>>> ssl = "somestring"
>>> if ssl:
...   print('pass')
... else:
...   print('fail')
... 
pass

Edit
When I would use if no_ssl != "" pylint gives a warning that I should use if only for that condition.

I also tested it with Jinja. I assigned two variables in the playbook:

    test_no_ssl: ''
    test_ssl: 'somestring'

test.j2:

{% if test_no_ssl is defined %}
    test_no_ssl - is defined - pass
{% else %}
    test_no_ssl - is defined - fail
{% endif %}
{% if test_no_ssl %}
    test_no_ssl - if - pass
{% else %}
    test_no_ssl - if - fail
{% endif %}
{% if test_ssl %}
    test_ssl - if - pass
{% else %}
    test_ssl -if - fail
{% endif %}

Output:

    test_no_ssl - is defined - pass

    test_no_ssl - if - fail

    test_ssl - if - pass

That is exactly what I need. Is it wrong to use only if?

@danopt danopt requested a review from widhalmt October 27, 2022 13:02
@danopt danopt added the enhancement New feature or request label Oct 27, 2022
@widhalmt
Copy link
Member

Only if can be misleading.

Why not remove the definition in defaults and us {% if variable is defined %}. That's more or less the ususal way to do it.

About the "" empty string... personally I would be ok with the playbook just failing when it's set to an empty string because that doesn't make any sense - at least to me.

So I see these options with their respective outcome

  • Variable is not defined: skip that string in the template
  • Variable is set to something that doesn't work like "": Just let the tasks run and fail
  • Variable is set to something useful: Works as expected

If you see that differently, I'll happily let myself get convinced.

@danopt danopt changed the title Enable SSL in haproxy.cfg if patroni_restapi_certfile is defined Enable SSL in haproxy.cfg if patroni_restapi_certfile is false Oct 28, 2022
@danopt
Copy link
Member Author

danopt commented Oct 31, 2022

@widhalmt You're right, it's hard to read, and also, in this way, I can see which role variables are really required or optional.

So I commented all unnecessary variables of the REST API of Patroni and changed the condition.

@danopt danopt changed the title Enable SSL in haproxy.cfg if patroni_restapi_certfile is false Enable SSL in haproxy.cfg if patroni_restapi_certfile is defined Nov 2, 2022
Copy link
Member

@widhalmt widhalmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as far as I can tell.

@danopt danopt merged commit 5422522 into netways Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants