Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
App Engine is giving me this error:
TemplateSyntaxError: expected token ')', got 'social'
template (/srv/templates/base.html:5)
I'm not clear why. Here's the beginning of the base.html template:
{% set navlinks = [('Home', '/'),
('Foo Bar', '/foo-bar'),
('News', '/news'),
('Contact', '/contact)] %}
{% set social_icons = [('social-icons/facebook.html', 'https://www.facebook.com/blah'),
('social-icons/twitter.html', 'https://twitter.com/blah'),
('social-icons/linkedin.html','https://www.linkedin.com/in/blah/')] %}
<!-- remainder of the template... -->
You transposed closing quote ' and ) in
('Contact', '/contact')] %}
Try:
{% set navlinks = [('Home', '/'),
('Foo Bar', '/foo-bar'),
('News', '/news'),
('Contact', '/contact)'] %}
{% set social_icons = [('social-icons/facebook.html', 'https://www.facebook.com/blah'),
('social-icons/twitter.html', 'https://twitter.com/blah'),
('social-icons/linkedin.html','https://www.linkedin.com/in/blah/')] %}
<!-- remainder of the template... -->
You missed a close quote after '/contact).
Related
I have this piece of code
---
- name: gather facts
hosts: all #
- hosts: proxy
tasks:
- blockinfile:
path: /etc/example
block: |
{% for n in groups['all'] %}
{{ hostvars[n]['ansible_default_ipv4']['address'] }}
{% endfor %}
if one node from the group all is down, the jinja loop is failing.
I did not find a solution to prevent that (tried with skip_untreachable: true without success for instance). Off course I can comment the down node in the inventory but this is neither convenient nor reliable.
How can I prevent that ?
I have the following variables in my playbook:
frontends:
- domain01.fr
- domain02.fr
- domain03.fr
- domain04.fr
I need to be able to write the following in a file via an Ansible playbook step:
tcp://domain01.fr:11211,tcp://domain02.fr:11211,tcp://domain03.fr:11211,tcp://domain04.fr:11211
I came up with the following solution, but I'm not pleased with it.
- name: Setting up Apache (2/2)
lineinfile:
path: /etc/opt/rh/rh-php56/php.ini
regexp: '^session.save_path ='
line: "session.save_path = 'tcp://{{ frontends | join(':11211,tcp://') }}'"
I can't hardwrite the domains inside the lineinfile method, because it depends a lot, plus there are situations where I only have 2 domains instead of 4.
Is it possible to have something like the following:
- name: Setting up Apache (2/2)
lineinfile:
path: /etc/opt/rh/rh-php56/php.ini
regexp: '^session.save_path ='
line: "session.save_path = '{% for frontend in frontends %} tcp://{% frontend %}:11211,{% endfor %}'"
Thank you in advance
Yes. It's possible. The line below
regexp: '^session.save_path ='
line: >-
session.save_path ={% for frontend in frontends %}
tcp://{{ frontend }}:11211{% if not loop.last %},{% endif %}{% endfor %}
gives
session.save_path = tcp://domain01.fr:11211, tcp://domain02.fr:11211, tcp://domain03.fr:11211, tcp://domain04.fr:11211
i want to create an dynamical playbook for my infrastructure.
i need this line in my config:
wsrep_cluster_address='gcomm://192.168.126.38,192.168.126.39,192.168.126.40'
my template looks like this:
wsrep_cluster_address = 'gcomm://{% for host in groups['db-server']%}{{hostvars[host]['ansible_host']}},{% endfor %}'
it works and looks like this on the host:
wsrep_cluster_address = 'gcomm://172.16.120.45,172.16.120.40,172.16.120.42,'
the last comma is breaking my nerves.
Is there a way to tell ansible not to comma the last entry of the loop?
Tanks for any help, have a great day
Found the solution, thanks to my developer.
wsrep_cluster_address = 'gcomm://{% for host in groups['db-server']%}{{hostvars[host]['ansible_host']}}{% if not loop.last %},{% endif %}{% endfor %}'
You saved my Day!
Also if you need line in config file like JSON:
nodelist = ["192.168.126.38","192.168.126.39","192.168.126.40"]
This is your Ansible for this:
nodelist={%for host in groups['mygroup']%}"{{hostvars[host].ansible_eth0.ipv4.address}}"{% if not loop.last %},{% endif %}{% endfor %}
Here is if full example:
- name: Create List of nodes to be added into Cluster
set_fact: nodelist={%for host in groups['mygroup']%}"{{hostvars[host].ansible_eth0.ipv4.address}}"{% if not loop.last %},{% endif %}{% endfor %}
- debug: msg=[{{nodelist}}]
- name: Set Cluster node list in config file
lineinfile:
path: "/etc/myfonfig.cfg"
line: "hosts: [{{ nodelist }}]"
as results you will have the following line in config file:
hosts: ["192.168.126.38","192.168.126.39","192.168.126.40"]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am posting the following JSON to Tomcat server but Tomcat server returns 400 without even calling the servlet -
[
{
"q": {
"field": "uri",
"value": "c:Data#part3"
},
"uri_pre_select": true
}
]
Inside the servlet the following code is deserializing the JSON -
// JSONObject reqJSONObj;
MyRequest[] data = gson.fromJson(reqJSONObj.toString(), MyRequest[].class);
When I remove the enclosing square brackets [ ] in the request JSON, then my servlet is called normally. This means there is something in the JSON, that is making it unacceptable to Tomcat.
But I don't have any clue why can't I post an array. Can anyone see a problem in the JSON that I am posting here ?
My mistake -
The handler method was accepting a JSONObject. When I changed the type to JSONArray it was getting called by Tomcat.
I am trying to create a sidebar-menu that looks like this.
iOS
-entry1
-entry2
-entry3
Web
-entry1
-entry2
Other
-entry1
-entry2
Each "post" (as in - the files in the dir "_posts") will have one (or more) categories in the meta-data (at the top of the file) and is to be listed underneath that header in the menu. So for example, if I make a post which has got "categories: iOS" it should be listed under the "iOS" header in the menu.
{% for cat in ["jekyll","ios","test"] %} // This is what I am unable to get right
{% for post in site.posts %}
{% if post.category == cat %}
{{ post.categories }} // test
<li>{{ post.title }}</li>
{% endif %}
{% endfor %}
{% endfor %}
Is it not possible to create an array on the fly like this? I am finding it really hard to google this specific question I have.
Alright to create an array on the current page I needed to use "front matter" i.e. the things on top of the pages surrounded by "---"
This is the solution:
Top of page:
---
cats: [1,2,3,asd]
---
Further down:
{% for c in page.cats %}
{{c}}<br/>
#loop through more here.
{% endfor %}
</body>