Bootstrap FreeKB - Ansible - Escape special characters using urlencode
Correct me if I am wrong but I think you may have updated the address bar to have https://www.freekb.net/Article?id=34 which is an invalid URL. If not, Contact Us
Ansible - Escape special characters using urlencode

Updated:   |  Ansible articles

There are two similiar but distinct filters that can be used to escape literal or special characters.

urlencode can be used to encode special characters in a string. In this example, the whitespace in "fo o" is encoded as %20.

---
- hosts: localhost
  tasks:
  - name: encode special characters
    debug:
      msg: "{{ 'fo o' | urlencode }}"
...

 

The following should be returned.

ok: [localhost] => {
    "msg": "fo%20o"
}

 

In this example, the long dash (also known as em dash) in ba–r will be encoded.

---
- hosts: localhost
  tasks:
  - name: encode special characters
    debug:
      msg: "{{ 'ba–r' | urlencode }}"
...

 

The following should be returned.

ok: [localhost] => {
    "msg": "ba%E2%80%93r"
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 5aa57e in the box below so that we can be sure you are a human.