Questions tagged [template]

28 questions
6
votes
2 answers

How to set environment variables dynamically for command?

I would like to use some kind of minimalistic template engine with pure bash and envsubst: user@host:~$ env -i FOO=foo BAR="bar baz" envsubst '$FOO,$BAR' \ <<< 'Hello "$FOO" and "$BAR"!' Hello "foo" and "bar baz"! Above works, but only contains…
5
votes
4 answers

Is there an easy way to do the equivalent of `sed ...` replacing the same line with multiple values?

I have a file where I want to replace some variables with data from a shell script. -A INPUT -i lo -s @LOCAL_IP@ -j ACCEPT Here I want to replace @LOCAL_IP@ with an IP address, I use the following: ... | sed -e 's/@LOCAL_IP@/192.168.1.1/' | ... I…
Alexis Wilke
  • 2,697
  • 2
  • 19
  • 42
2
votes
1 answer

Simple template engine for bash, that can use csv data?

I'd often like to quickly take some data, and apply it to a template in bash. e.g. imagine doing the following $ seq 1 2 | eztemplate 'this is a {1} test' this is a 1 test this is a 2 test $ eztemplate 'this is a {1} test' hi 'there now' …
Brad Parks
  • 1,619
  • 3
  • 22
  • 38
2
votes
4 answers

Use the output of a command as input to the same command in a loop

So I'm trying to find a template for bash/shell script that essentially run a command, let's call it "command1" using an input "X" and then use the output of command1 on itself...but in a loop. Here a real world example: echo "hello" | cut…
Nordine Lotfi
  • 2,200
  • 12
  • 45
2
votes
0 answers

Is there a way to have code templates for "if", "for" (or) for any multiline commands in terminal?

Code templates are handy and help in finishing codes without error. I am aware that notepad editors like atom provide code templates for if and for loop for bash. Also aware that man pages provide assistance in understanding the syntax. For e.g.,…
Praveen Kumar-M
  • 584
  • 5
  • 14
2
votes
0 answers

Rename a template when creating it

I added the "Empty file" (empty text document) to the Templates folder. Is possible to rename it automatically when I create it? As when using new folder. My file manager is nautilus.
Scorpion
  • 737
  • 1
  • 7
  • 18
2
votes
1 answer

A utility to append content into a file, if this content isn't already in the file (even in part)

Is there a *Nix utility by which I could append content to a file (say, append the content of a template file into the end of a second file), only if the content isn't already available in the second file, partially or fully? One could use this grep…
1
vote
1 answer

Adding host to Zabbix 6.2 through ansible failed (worked on 6.0)

I have an issue with the conversion (migration) from zabbix 6.0 to zabbix 6.2. I have a playbook in Ansible to automatically add a host to zabbix with some host_groups and Templates predefined which worked on Zabbix 6.0 but in 6.2 zabbix added the…
SHLelieveld
  • 331
  • 2
  • 4
  • 21
1
vote
1 answer

systemd start stop enable and disable multiple services with one target unit

I have created a target file /etc/systemd/system/watch-for-sync-need-all.target [Unit] Description=systemd target to group services for all folders that create a sync need by…
bejo
  • 165
  • 4
  • 16
1
vote
3 answers

Generate templates in yaml from a CSV file

I am trying to create yaml files from a template using my variables. My yaml template look like this number: {{NUMBER}} name: {{NAME}} region: {{REGION}} storenum: {{STORENUM}} clients: {{CLIENTS}} tags: {{TAGS}} storename:…
Jo0l
  • 11
  • 2
1
vote
1 answer

how to join inventory items in a comma delimited list?

I have ansbile inv # cat inv [all] vm1 vm2 I want to extract them in a comma delimited list using Jinja template so I add jinja template # cat comb_list.j2 {{ groups['all'] | map('extract', hostvars, ['item']) | join(',') }}" but I guess item is…
Sollosa
  • 1,887
  • 4
  • 19
  • 32
1
vote
1 answer

Simple and standard way to generate files based on templates?

For my projects I need a way to generate some files based on template ones. I envision it this way: a template file contains data with something like {{var1}} in place of the variables to be replaced other file contains a list of key = value…
kosmosu05
  • 53
  • 1
  • 7
1
vote
1 answer

Ansible - template from dictionary item

Ansible - template from dictionary item 1'st: Trying to write task which creates files from template NODES: node1: server: host1 script: manage1 node2: server: host2 script: manage2 node3: server: host3 - name: Create…
hubizx
  • 11
  • 2
1
vote
1 answer

for loop in jinja2

Please explain to me how can I fix this problem? i have this file defaults/main.yml --- node1: ip: 1.1.1.1 node2: ip: 2.2.2.2 node3: ip: 3.3.3.3 Now, I want in template file ip.j2 by for loop access the IPs of each server and save in address…
pyramid13
  • 609
  • 6
  • 16
  • 31
0
votes
0 answers

HELM get first element from a helpers template

I have some template inside _helpers.tpl file like this {{- define "clusterNodes" }} - ip: "192.168.7.10" hostnames: - "m1" - ip: "192.168.7.20" hostnames: - "w1" - ip: "192.168.7.30" hostnames: - "w2" {{- end }} and I want to fetch…
Sollosa
  • 1,887
  • 4
  • 19
  • 32
1
2