jinja2

Ansible/Jinja: condition with an undefined statement

岁酱吖の 提交于 2020-01-03 04:09:10
问题 I need to iterate over all hosts and generate config file for hosts that are not contained in group somegroup : {% for host in groups.all if host not in groups['somegroup'] %} But if somegroup does not exist, it fails (argument of type 'StrictUndefined' is not iterable). How do I write this correctly to avoid two different for cycles: {% if groups['somegroup'] is defined %} {% for host in groups.all if host not in groups['somegroup'] %} ... {% endfor %} {% else %} {% for host in groups.all %}

Using {{ and }} in ansible shell command

淺唱寂寞╮ 提交于 2020-01-02 08:44:10
问题 I have this in my playbook: - name: Get facts about containers shell: "docker ps -f name=jenkins --format {%raw%}{{.Names}}{% endraw %}" register: container Note, that I inserted the {%raw%} and {%endraw%} so that ansible does not evaulate the '{{'. If I run this, I get this error: fatal: [localhost]: FAILED! => {"failed": true, "msg": "{u'cmd': u'docker ps -f name=jenkins --format {{.Names}}', u'end': u'2017-01-19 10:04:27.491648', u'stdout': u'ecs-sde-abn-17-jenkins-ec8eccee8c9eb8e38f01', u

Base64 Decode String in jinja [duplicate]

瘦欲@ 提交于 2020-01-02 05:42:08
问题 This question already has answers here : Python base64 data decode (9 answers) Closed 3 years ago . I'm new to using python and flask and really like it. I'm returning a query to be displayed in a jinja template and one of my columns being returned has base64 data. How do I decode that data and display it. 回答1: In jinja To work with Base64 encoded strings: {{ encoded | b64decode }} {{ decoded | b64encode }} For more http://docs.ansible.com/ansible/playbooks_filters.html 回答2: You can try to

How to solve a UnicodeDecodeError?

空扰寡人 提交于 2020-01-02 03:11:29
问题 I get a strange error message when trying to read non-ascii from the datastore: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128) Traceback (most recent call last): File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 1511, in __call__ rv = self.handle_exception(request, response, e) File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 1505, in __call__ rv = self.router.dispatch(request, response) File "

How to solve a UnicodeDecodeError?

一个人想着一个人 提交于 2020-01-02 03:11:12
问题 I get a strange error message when trying to read non-ascii from the datastore: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128) Traceback (most recent call last): File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 1511, in __call__ rv = self.handle_exception(request, response, e) File "/base/data/home/apps/s~myapp-www/events.355951895377615944/webapp2.py", line 1505, in __call__ rv = self.router.dispatch(request, response) File "

compare two variables in jinja2 template

风格不统一 提交于 2020-01-02 01:55:13
问题 Given I have two variables {{ profile }} with a value "test" and {{ element.author }} again with the value "test". In jinja2 when I try to compare them using an if, nothing shows up. I do the comparison as follows: {% if profile == element.author %} {{ profile }} and {{ element.author }} are same {% else %} {{ profile }} and {{ element.author }} are **not** same {% endif %} I get the output test and test are not same Whats wrong, how can I compare? 回答1: I have the same problem, two variables

How can I pass JSON data into a Nunjucks template?

此生再无相见时 提交于 2020-01-02 01:16:18
问题 I want to use Nunjucks templates but want to pass in my own JSON data to be used on the templates. The documentation here is pretty sparse. https://mozilla.github.io/nunjucks/templating.html Thank you. 回答1: You can use gulp-data which allows you to pass json files to the task runner you're using to render Nunjucks. gulp.task('nunjucks', function() { return gulp.src('app/pages/**/*.+(html|nunjucks)') // Adding data to Nunjucks .pipe(data(function() { return require('./app/data.json') })) .pipe

How can I use Jinja with Twisted?

橙三吉。 提交于 2020-01-01 14:52:07
问题 I'm planning up a discussion software using Python with Twisted, Storm, and Jinja. The problem is that Jinja was not made for Twisted or asynchronous socket libraries, and the performance provided by using Twisted is why I don't plan on using Flask. So, how can I have Twisted render webpages using Jinja? 回答1: You can render web pages using Jinja the same way you would use any other Python library in Twisted. You just call into it. This will work fine with Twisted, although you may run into

How can I use Jinja with Twisted?

三世轮回 提交于 2020-01-01 14:51:15
问题 I'm planning up a discussion software using Python with Twisted, Storm, and Jinja. The problem is that Jinja was not made for Twisted or asynchronous socket libraries, and the performance provided by using Twisted is why I don't plan on using Flask. So, how can I have Twisted render webpages using Jinja? 回答1: You can render web pages using Jinja the same way you would use any other Python library in Twisted. You just call into it. This will work fine with Twisted, although you may run into

how to use variable to pass filter name in jinja2 templates

余生长醉 提交于 2020-01-01 10:09:26
问题 I have defined some filters and use it very often. I need to do some A/B tests and for this in some situations some of filters should work in different way. Easiest way to do this would be create a variable in template which store a filter name. something like this: {% set filter_name = 'some_name' %} {{ my_value|filter_name }} But when I try this, I get an error: TemplateAssertionError: no filter named 'filter_name' Please help me to find a solution. 回答1: By doing {% set filter_name = 'some