I need to create a cronjob for renewal lets encrypt certificates.
The final command should looks like this:
certbot certonly --no-eff-email -m [email protected] --redirect --agree-tos --non-interactive --standalone -d mydomain.com -d www.mydomain.com -d domain1.mydomain.com -d domain1a.mydomain.com -d domain2.mydomain.com -d domain2a.mydomain.com
I have the following variables:
nginx:
vhost:
- name: mydomain.com
server_name:
- mydomain.com
- www.mydomain.com
...
...
- name: domain1.mydomain.com
server_name:
- domain1.mydomain.com
- domain1a.mydomain.com
...
...
- name: domain2.mydomain.com
server_name:
- domain2.mydomain.com
- domain2a.mydomain.com
...
...
...
How can I get this values from nginx.vhost.server_name
of each vhost
in one command?
2
Answers
Here’s one example; I’m using a
debug
task instead of, say, acommand
task, because I don’t want to actually run anything on my computer, but this should demonstrate the technique:We use the
map
filter to extract the value ofserver_name
from each item in thenginx.vhost
list, and then pass the result toflatten
to get a single list instead of a list of lists.Running the above will generate as output:
For example
gives