I am trying to loop over all items in a Python cookiecutter json list and run a bash command based on each item.
Setup
I have the following cookiecutter.json
:
{
"directory_name": "df-sharp",
"servers": ["db", "web"],
"myweb_provisioner": "webck"
}
I have {{cookiecutter.myweb_provisioner}}.sh
, which contains this jinja2
code:
{% for server in cookiecutter.servers %}
mkdir -p ~/myproj/host_types/{{ server }}
{% endfor %}
Problem
When I run cookiecutter create-server-tree
, I get the following:
Select servers:
1 - db
2 - web
Choose from 1, 2 [1]: 2
and the contents in webck.sh
are:
mkdir -p ~/myproj/host_types/w
mkdir -p ~/myproj/host_types/e
mkdir -p ~/myproj/host_types/b
The Select
menu should not appear. I do not want to choose between the 2 elements in the list. I want to loop over them and construct 2 bash commands - one command per element. I am trying to loop over the list like shown here or here.
What I want
This is what I want: cookiecutter create-server-tree
should produce webck.sh
which contains the following:
mkdir -p ~/myproj/host_types/db
mkdir -p ~/myproj/host_types/web
How can I iterate over the servers
list and use each of the list elements (instead of one character at a time)?