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

Problem with special string %{%s}t when calling update_reverseproxy_conf #53

Closed
alwayslearning321 opened this issue Jan 5, 2018 · 3 comments

Comments

@alwayslearning321
Copy link

alwayslearning321 commented Jan 5, 2018

Trying to port existing settings of "request-log-format" from older version to ISAM 9. The required string is

request-log-format = { \"seconds\": \"%{%s}t\" }

But the "%{%s}t" part always caused problem in "update_reverseproxy_conf". The yml file I used is as below:

---
- name: Run some commands
  hosts: all
  connection: local
  vars:
    username: "admin"
    password: "password1234"
    lmi_port: "443"
    log_level: "CRITICAL"
    force: True
    start_config_wait_time: 120
  roles:
    - role: update_reverseproxy_conf
      update_reverseproxy_conf_reverseproxy_id: "TestInstance"
      update_reverseproxy_conf_entries:
      - stanza_id: "logging"
        entry_id: "request-log-format"
        value_id: " \"seconds\": \"%{%s}t\" "

The error message is:

FAILED! => {
    "failed": true, 
    "msg": "[{u'entry_id': u'request-log-format', u'stanza_id': u'logging', u'value_id': u' \"seconds\": \"%{%s}t\" '}]: template error while templating string: Encountered unknown tag 's'.. String:  \"seconds\": \"%{%s}t\" "
}

If I remove the 2 "%"s then it works, but we need the specific string to be there as lots of log parsing program relies on the exact format to work properly. Also tried various escape characters but none can achieve what we need, some examples listed below:

1) " { \"seconds\": \"%{%s}t\" } "  error: Encountered unknown tag 's'
2) ' { \"seconds\": \"%{%s}t\" } '  error: Encountered unknown tag 's'
3) ' { \"seconds\": \"%{\%s}t\" } ' no error but with incorrect result extra back slash before %s)  request-log-format = { "seconds": "%{\%s}t" }
4) ' { \"seconds\": \"\%{%s}t\" } ' error: Encountered unknown tag 's'
5) " { \"seconds\": \"%{%%s}t\" } "  error: tag name expected
6) " { \"seconds\": \"%%{%s}t\" } "  error: tag name expected
7) '{% raw %}{ "seconds": "%{%s}t" }{% endraw %}'  error: Encountered unknown tag 's'
8) !unsafe ' { "seconds": "%{%s}t" } '  error: SyntaxError: invalid syntax MODULE FAILURE

Also tried below .yml but still failed

---
- name: Run some commands
  hosts: all
  connection: local
  vars:
    username: "admin"
    password: "password1234"
    lmi_port: "443"
    log_level: "CRITICAL"
    force: True
    start_config_wait_time: 120
    starter_value: " { \"seconds\": \"${$s}t\" } "       
  roles:
    - role: update_reverseproxy_conf
      update_reverseproxy_conf_reverseproxy_id: "TestInstance"
      update_reverseproxy_conf_entries:
      - stanza_id: "logging"
        entry_id: "request-log-format"
        value_id: "{{ starter_value | regex_replace('\\$','%') }}"

Can see the "regex_replace" part is working as the final "value_id" string has the "$" correctly changed to "%". The error message shown below is the same as before (Encountered unknown tag 's').

FAILED! => {
    "failed": true, 
    "msg": "{u'entry_id': u'request-log-format', u'stanza_id': u'logging', u'value_id': u' { \"seconds\": \"%{%s}t\" } '}: template error while templating string: Encountered unknown tag 's'.. String:  { \"seconds\": \"%{%s}t\" } "
}

Also raised a question in
stackoverflow but all of the suggestions received failed.

Plus, how do we know whether it's Ansible or ISAM or the isam-ansible-roles code that throws the error?

Please help. Thanks.

@ram-ibm
Copy link
Collaborator

ram-ibm commented Jan 8, 2018

There is Ansible logic that tries to apply jinja2 conversions on strings - I believe that is what is causing the issue here. We got around it by converting the "%" to "\x25". Please try that.

If you run playbooks with -vvv you get detailed traces of what Ansible is doing as well as the python code that is invoked to make the REST API call to the appliance.

@alwayslearning321
Copy link
Author

Test and confirmed if I changed the last line to as below, (1) replacing "%" with "\x25" and (2) enclose the whole string with single quotes (doesn't work if use double quotes),

value_id: '{ \"seconds\": \"\x25{\x25s}t\" }'

then it correctly updates the "request-log-format" key with the expected result:

request-log-format = { "seconds": "%{%s}t" }

Thanks for the help, will close the issue as resolved.

@alwayslearning321
Copy link
Author

issue resolved

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

2 participants