Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

2 votes
1 answers
140 views
Mutt: auto-reply with template?
In Mutt, I would like to configure something akin to the "Reply with Template" message filter action from Thunderbird. I.e., for a given message, I would like to be able to easily (read: keyboard shortcut) send a reply with predefined subject and body. Is this even possible? Thanks.
In Mutt, I would like to configure something akin to the "Reply with Template" message filter action from Thunderbird. I.e., for a given message, I would like to be able to easily (read: keyboard shortcut) send a reply with predefined subject and body. Is this even possible? Thanks.
nvx (65 rep)
Aug 25, 2024, 02:40 PM • Last activity: Sep 8, 2024, 08:51 AM
0 votes
1 answers
833 views
.Files.Glob pattern for a helm configmap
I have directory structure like this $ tree . . ├── Chart.yaml ├── datafiles │   ├── index.html │   ├── style.css │   ├── exclude.txt │   └── text │   ├── file1.txt │   ├── file2.txt I want to create configmaps with these conditions 1. Incl...
I have directory structure like this $ tree . . ├── Chart.yaml ├── datafiles │   ├── index.html │   ├── style.css │   ├── exclude.txt │   └── text │   ├── file1.txt │   ├── file2.txt I want to create configmaps with these conditions 1. Include files from datafiles directory only, and exclude any child directory like text 2. ability to exclude selective file(s) from parent dir like exclude.txt 3. able to templatize values from values file, say some values in index.html will be coming from values.yaml file, so use of tpl function is expected. I am able to create configmaps by using below pattern, but it tends to include all files in child directories too, also unable to include tpl function for files like index.html --- apiVersion: v1 kind: ConfigMap metadata: name: tpl-index data: {{ $currentScope := . }} {{- range $path, $_ := .Files.Glob "datafiles/**" }} {{- if not .Files.IsDir $path }} {{ (base $path) }}: |- {{ tpl .Files.Get $path | indent 4 }} {{- end }} {{- end }}
Sollosa (1993 rep)
Feb 14, 2024, 07:28 PM • Last activity: Jun 7, 2024, 11:23 AM
0 votes
1 answers
1341 views
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 hostnames of first element in above for following yaml apiVersion:...
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 hostnames of first element in above for following yaml apiVersion: apps/v1 kind: Deployment metadata: name: nginx2 spec: replicas: 1 selector: matchLabels: app: nginx2 template: metadata: labels: app: nginx2 spec: nodeName: "{{ (index (index $clusterNodes "clusterNodes") 0).hostnames.0 }}" containers: - name: nginx2 image: nginx:alpine imagePullPolicy: IfNotPresent so that this entry look like below nodeName: m1
Sollosa (1993 rep)
Jul 6, 2023, 06:47 PM • Last activity: Sep 20, 2023, 07:58 AM
1 votes
1 answers
1825 views
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 Template_groups and now the playbook complains that...
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 Template_groups and now the playbook complains that it can't find the templates anymore. Here is a part of the playbook:
- name: ZABBIX - Create or update host
  local_action:
    module: community.zabbix.zabbix_host
    server_url: https://monitor.localdomain 
    login_user: "a*******a"
    login_password: "S*********************y"
    host_name: "{{ ansible_hostname }}"
    visible_name: "{{ ansible_hostname }}"
    tls_psk_identity: "{{ ansible_hostname }}"
    tls_accept: 2
    tls_connect: 2
    tls_psk: "{{ psk.stdout }}"
    host_groups:
      - Linux servers
    link_templates:
      - Template OS Linux
      - Template YUM Updates
    status: enabled
    state: present
    inventory_mode: automatic
    interfaces:
      - type: 1
        main: 1
        useip: 1
        ip: "{{ ansible_default_ipv4.address }}"
      - type: 2
        main: 1
        useip: 1
        ip: "{{ ansible_default_ipv4.address }}"
        details:
          community: "{$SNMP_COMMUNITY}"
          version: 2
    proxy: "ZabbixProxy"
  vars:
    ansible_python_interpreter: "/usr/bin/python3"
  tags:
    - zabbix-agent
This worked perfectly on 6.0 and added the servers to the host_group Linux Servers and added the templates OS Linux and YUM updates with no issue. Now in 6.2 it complains that it can't find the templates, and if I outhash the templates it complains that it can't find the host_group. When I outhash that it complains that it has to have at least 1 host group.... :| I tried all combinations of templates, as the templates are now in the template group: "Templates/Operating Systems" I even added a template_groups: section in the playbook as that is a valid field in rust, but apparently it is not for ansible as now it complains on a invalid module found. How do I change/add the templategroup the correct way...? Thanks for reading and thinking along with me.
SHLelieveld (443 rep)
Dec 30, 2022, 09:11 AM • Last activity: Jul 2, 2023, 08:26 PM
2 votes
1 answers
333 views
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' this is a hi test this is a there now test $ eztemplate /tmp/t...
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' this is a hi test this is a there now test $ eztemplate /tmp/template /tmp/alphabet | head this is a a test of this system a this is a b test of this system b ... I've wrote a very simple bash script that does this, but was considering allowing multiple parameters, like CSV style data, per line of data. ### Does something better than my little script already exist, given the following? - I want it to require only basic unix posix tools, and commonly installed things like perl or awk, but requires no modules be installed additionally by perl, for example - It can accept multiple columns of data, per line of data in the data file. - Basically is one bash script that doesn't require installing anything else :D - A side intent is to allow others that aren't great at bash scripting to have a simple tool to process templates for repeating data The data and template will vary greatly, but the first example I wanted to do it with was apply 4 ids to a JSON payload *template* { "tenantId": "{1}", "key": "some.key", "value": "some.value" } *data* my/super/01cbf4e9779649038f0bd753747c8b26 my/test/01cbf4e9779649038f0bd753747c8b26 ez/test/01cbf4e9779649038f0bd753747c8b26 rad/data/df3a47fed39d453f836f9b2196332029 ## eztemplate #!/usr/bin/env bash DIR="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"; PATH="$DIR:$PATH" function show_help() { ME=$(basename "$0") IT=$(cat <
Brad Parks (1769 rep)
Mar 3, 2023, 04:18 PM • Last activity: Mar 3, 2023, 07:53 PM
1 votes
1 answers
1488 views
Is the systemd dbus service under org.freedesktop.systemd1 able to manage unit templates?
I'm writing a program, which is managing a lot of instances of some unit templates. My plan was, to use the dbus service of systemd to do so. But apparently, the interface on org.freedesktop.systemd1.Manager can only manage either units, which are already loaded, or unit**Files**. The methods, worki...
I'm writing a program, which is managing a lot of instances of some unit templates. My plan was, to use the dbus service of systemd to do so. But apparently, the interface on org.freedesktop.systemd1.Manager can only manage either units, which are already loaded, or unit**Files**. The methods, working on unit files dont't work for enabling or starting template instances, because they apparently aren't designed to work with unit names which don't have a unit file with an exactly matching name, and don't find the template corresponding to the matching instance. The methods working on loaded units also need a unit with that exact name to be already loaded, which isn't the case with units, which haven't been instantiated yet. Also the documentation of the interface doesn't really talk about templates. Isn't this interface supposed to be equally powerful as the systemctl command? Am I just missing something about the interface? Or is there another interface, specifically for templates, which I didn't find yet? or is there just not way, to do this stuff with systemd?
Niclas (11 rep)
Aug 4, 2022, 07:40 AM • Last activity: Aug 6, 2022, 04:35 PM
8 votes
2 answers
3324 views
How to set environment variables dynamically for command?
I would like to use some kind of minimalistic template engine with pure bash and `envsubst`: ```sh user@host:~$ env -i FOO=foo BAR="bar baz" envsubst '$FOO,$BAR' \ Reason: `set -x` shows that the argument for `env` becomes one giant string : ```sh + env -i 'FOO='\''foo'\''' 'BAR='\''bar' 'baz'\''' e...
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' \
  Reason: set -x shows that the argument for env becomes one giant string:
sh + env -i 'FOO='\''foo'\''' 'BAR='\''bar' 'baz'\''' envsubst #... env: ‘baz'’: No such file or directory ``` I must have missed a shell escape lession (again...). How might I rewrite last example to work properly?
user00705358365913 (83 rep)
Jul 22, 2022, 05:30 PM • Last activity: Jul 22, 2022, 07:56 PM
1 votes
1 answers
2637 views
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 changes After=multi-user.target Wants=watch-for-sync-need@_sl_home_sl_.service Wants=watch-for-sync-need@_sl_stream_sl_.servi...
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 changes After=multi-user.target Wants=watch-for-sync-need@_sl_home_sl_.service Wants=watch-for-sync-need@_sl_stream_sl_.service [Install] Also=watch-for-sync-need@_sl_home_sl_.service Also=watch-for-sync-need@_sl_stream_sl_.service Its purpose is to be able to start, stop, enable or disable all in the target specified systemd template services /etc/systemd/system/watch-for-sync-need@.service [Unit] Description=watch sync folders for changes then flag sync need and set rtcwake BindsTo=watch-for-sync-need-all.target After=watch-for-sync-need-all.target [Service] User=root Group=root Type=simple ExecStart=/bin/bash /etc/custom/notify-on-change %i Restart=on-failure RestartSec=3 [Install] WantedBy=watch-for-sync-need-all.target In case it has to deal with my problem I post the called script content of /etc/custom/notify-on-change #! /usr/bin/env bash inotifywait -q -m -r -e modify,delete,create "${1//_sl_//}" | while read DIRECTORY EVENT FILE do echo "yes" > /etc/custom/log/sync-needed bash /etc/custom/set-rtcwake systemctl stop watch-for-sync-need-all.target done If there is a change in the folders /home/ or /stream/ inotifywait notices that, flags a sync need, sets a computer self wakeup in the upcoming night at 3 o'clock and stops the services. (There is a cronjob on the machine that syncs to another computer at some minutes past 3 o'clock, if a sync need is flagged. The computer shuts itself down, when not used. Like that, I can work on my computer and make changes in /home/ or /stream/ and then and only then a sync will be started shortly automatically.) My Problem is, that I can't enable my target adequately. The target can be started or stopped without problems. That means, that both "sub"-units are running. Enabling does not give out any warnings and creates corresponding links in the directory /etc/systemd/system/watch-for-sync-need-all.target.wants but when my machine boots, the "sub"-units are not running. After a new boot I get the following output of systemctl status watch-for-sync-need-all.target watch-for-sync-need-all.target - systemd target to group services for all folders that create a sync need by ch> Loaded: loaded (/etc/systemd/system/watch-for-sync-need-all.target; indirect; vendor preset: enabled) Active: inactive (dead)enter code here or systemctl status watch-for-sync-need@_sl_home_sl.service watch-for-sync-need@_sl_home_sl.service - watch sync folders for changes then flag sync need and set rtcwake Loaded: loaded (/etc/systemd/system/watch-for-sync-need@.service; disabled; vendor preset: enabled) Active: inactive (dead) How can I make systemd start the target (all "sub"-units) at system boot?
bejo (175 rep)
Mar 8, 2022, 09:34 PM • Last activity: Mar 31, 2022, 09:26 PM
1 votes
3 answers
3323 views
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: {{STORENAME}} employee: {{EMPLOYEE}} products: {{PRODUCTS}} But my variables...
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: {{STORENAME}} employee: {{EMPLOYEE}} products: {{PRODUCTS}} But my variables are in a CSV file; the structure is the variables. Number - Name - Region - Storenum StoreX - StoreX - New York - 30 I now have a little script to create from a template with the variable parameters and the template like this: script.sh template.yml -f variables.txt. And my result looks like this number: 37579922 name: Store1 region: New York storenum: 32 clients: 100 tags: stores storename: Store newyork employee: 10 products: 200 But I can only do one at a time. Is there any way to read the CSV parameters and send to the program and generate, for example, Template1,Template2,etc from the CSV parameters? #!/bin/bash readonly PROGNAME=$(basename $0) config_file="" print_only="false" silent="false" usage="${PROGNAME} [-h] [-d] [-f] [-s] -- where: -h, --help Show this help text -p, --print Don't do anything, just print the result of the variable expansion(s) -f, --file Specify a file to read variables from -s, --silent Don't print warning messages (for example if no variables are found) examples: VAR1=Something VAR2=1.2.3 ${PROGNAME} test.txt ${PROGNAME} test.txt -f my-variables.txt ${PROGNAME} test.txt -f my-variables.txt > new-test.txt" if [ $# -eq 0 ]; then echo "$usage" exit 1 fi if [[ ! -f "${1}" ]]; then echo "You need to specify a template file" >&2 echo "$usage" exit 1 fi template="${1}" if [ "$#" -ne 0 ]; then while [ "$#" -gt 0 ] do case "$1" in -h|--help) echo "$usage" exit 0 ;; -p|--print) print_only="true" ;; -f|--file) config_file="$2" ;; -s|--silent) silent="true" ;; --) break ;; -*) echo "Invalid option '$1'. Use --help to see the valid options" >&2 exit 1 ;; # an option argument, continue *) ;; esac shift done fi vars=$(grep -oE '\{\{[A-Za-z0-9_]+\}\}' "${template}" | sort | uniq | sed -e 's/^{{//' -e 's/}}$//') if [[ -z "$vars" ]]; then if [ "$silent" == "false" ]; then echo "Warning: No variable was found in ${template}, syntax is {{VAR}}" >&2 fi fi # Load variables from file if needed if [ "${config_file}" != "" ]; then if [[ ! -f "${config_file}" ]]; then echo "The file ${config_file} does not exists" >&2 echo "$usage" exit 1 fi source "${config_file}" fi var_value() { eval echo \$$1 } replaces="" # Reads default values defined as {{VAR=value}} and delete those lines # There are evaluated, so you can do {{PATH=$HOME}} or {{PATH=pwd}} # You can even reference variables defined in the template before defaults=$(grep -oE '^\{\{[A-Za-z0-9_]+=.+\}\}' "${template}" | sed -e 's/^{{//' -e 's/}}$//') for default in $defaults; do var=$(echo "$default" | grep -oE "^[A-Za-z0-9_]+") current=var_value $var # Replace only if var is not set if [[ -z "$current" ]]; then eval $default fi # remove define line replaces="-e '/^{{$var=/d' $replaces" vars="$vars $current" done vars=$(echo $vars | sort | uniq) if [[ "$print_only" == "true" ]]; then for var in $vars; do value=var_value $var echo "$var = $value" done exit 0 fi # Replace all {{VAR}} by $VAR value for var in $vars; do value=$(var_value $var | sed -e "s;\&;\\\&;g" -e "s;\ ;\\\ ;g") # '&' and is escaped if [[ -z "$value" ]]; then if [ $silent == "false" ]; then echo "Warning: $var is not defined and no default is set, replacing by empty" >&2 fi fi # Escape slashes value=$(echo "$value" | sed 's/\//\\\//g'); replaces="-e 's/{{$var}}/${value}/g' $replaces" done escaped_template_path=$(echo $template | sed 's/ /\\ /g') eval sed $replaces "$escaped_template_path"
Jo0l (11 rep)
Oct 2, 2021, 06:34 PM • Last activity: Oct 21, 2021, 11:49 PM
1 votes
1 answers
2597 views
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 not a hostvars, so throws error I want end file to loo...
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 not a hostvars, so throws error I want end file to look like this # cat comb_list vm1,vm2
Sollosa (1993 rep)
Sep 19, 2021, 02:09 PM • Last activity: Sep 19, 2021, 02:43 PM
2 votes
4 answers
1585 views
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 -c2- ``` which will remove the first character at the be...
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 -c2-
which will remove the first character at the beginning of the input string and output:
ello
Now, the above is just an example to illustrate the template mentioned above. Following this example, how could i use *command1* output:
echo "hello" | cut -c2-
But as input, in a loop, either indefinite loop or until only one byte/character remain. So that i don't need to copy/paste the output and replace it with the old input:
echo "ello" | cut -c2-
Or need to use multiple pipe which would be too slow/inefficient. **Simpler Explanation** Using manual action, this would be the replacement of me(the user) copy pasting the output of the command i gave as example (or the pseudo code i described earlier) and use that as input for that same command, repeating that same action until "one" byte or char remain.
Nordine Lotfi (2472 rep)
Jan 13, 2021, 05:50 PM • Last activity: Jan 14, 2021, 01:23 PM
0 votes
2 answers
216 views
how to fail on first error when using bash as a template tool
I am looking for a better version of `set -e`. That better version should just work™. I briefly read [BashFaq/105](http://mywiki.wooledge.org/BashFAQ/105) and tried [this insane approach](https://fvue.nl/wiki/Bash:_Error_handling#Solutions_revisited:_Combining_the_tools), but I still do not know how...
I am looking for a better version of set -e. That better version should just work™. I briefly read [BashFaq/105](http://mywiki.wooledge.org/BashFAQ/105) and tried [this insane approach](https://fvue.nl/wiki/Bash:_Error_handling#Solutions_revisited:_Combining_the_tools) , but I still do not know how to fail on error. My use case is that I would like to generate a text file from a template like this:
#!/usr/bin/env bash

# none of these options helped to get the behavior I want: stop on first error
# set -euo pipefail
# shopt -s inherit_errexit
# set -o errexit
# trap ERR

cat 

MYAPP_DATABASE_PASSWORD=

MYAPP_USER_PASSWORD=

MYAPP_CONFIGURATION_DATE=
if there is a typo in SecureRandom then erb immediately exits with a failure. **How to achieve this crash-on-failure behavior with bash?**
Julius (101 rep)
Jan 2, 2021, 06:21 PM • Last activity: Jan 4, 2021, 01:11 AM
1 votes
1 answers
1172 views
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` values * after applying a tool, a new file with co...
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 values * after applying a tool, a new file with concrete values should be generated Instead of the 2nd file, a list of key = value pairs could be provided via the command line or, which is the same thing, some keys may require environmental variables instead of the keys-value in the 2nd file. Are there **standard and well known utilities** used in Linux/Unix world that can do that?
kosmosu05 (83 rep)
Sep 27, 2020, 11:27 AM • Last activity: Sep 27, 2020, 12:31 PM
1 votes
1 answers
1362 views
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 files from templates template: src: "templ.j2" dest: "/etc/init.d/{{item.key}}...
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 files from templates
  template:
    src: "templ.j2"
    dest: "/etc/init.d/{{item.key}}"
  loop: "{{NODES|dict2items}}"
  when: "{{ 'script' in item.value }}"
Above creates files:
/etc/init.d/node1
/etc/init.d/node2
I can't find a way to get:
/etc/init.d/manage1
/etc/init.d/manage2
2'nd question: during looking for above changed dictionary into list of hashes, ( I'd rather stay with dictionaries ):
NODES:
  - node1:
    server: host1
    script: manage1
  - node2:
    server: host2
    script: manage2
for above list simple file creation works correctly:
- name: Create files
  file:
    path: "/etc/init.d/{{item.script}}"
    state: touch
  with_items: "{{ NODES }}"
but analogical file creation from template does not:
- name: Create files template
  file:
    dest: "/etc/init.d/{{item.script}}"
    src: templ.j2
  with_items: "{{ NODES }}"
I'm starting with Ansible, and is not easy to understand especially second case.
hubizx (11 rep)
Apr 26, 2020, 05:00 PM • Last activity: Jul 30, 2020, 07:22 PM
0 votes
0 answers
241 views
Create VM from template , Hostname issue
I created a VM from RHEL ISO Fle, and followed some steps to cleanup nic details and also inserted a systemd script to create machine id. Converted VM to template, However when i spin a new VM with new hostname via template, it has same Hostname as template. Can you please direct what i missed here,...
I created a VM from RHEL ISO Fle, and followed some steps to cleanup nic details and also inserted a systemd script to create machine id. Converted VM to template, However when i spin a new VM with new hostname via template, it has same Hostname as template. Can you please direct what i missed here, I went through lot of documents found online nothing helped me out. New to VMware world.Thanks
Rame (1 rep)
Jul 19, 2020, 09:29 PM • Last activity: Jul 20, 2020, 12:09 AM
0 votes
1 answers
992 views
ansible playbook with jinja2 loop
I need to write a playbook using jinja2 tamplate inorder to write firewalld rule in ansible. For that I wrote ``` --- - name: Firewalld check hosts: localhost become: yes tasks: - name: Allow ICMP traffic firewalld: rich_rule: rule family='ipv4' source address=" {{ source }} " protocol value="icmp"...
I need to write a playbook using jinja2 tamplate inorder to write firewalld rule in ansible. For that I wrote
---
- name: Firewalld check
  hosts: localhost
  become: yes

  tasks:
  - name: Allow ICMP traffic
    firewalld:
      rich_rule: rule family='ipv4' source address=" {{ source }} " protocol value="icmp" accept
      permanent: no
      state: enabled
in template and
---

- name: Firewalld config
  hosts: localhost
  become: yes

  vars:
    source:
       - 172.16.2.114
       - 172.16.2.115
  tasks:

  - name: Rules
    template:
      src: playtem.yml.j2
      dest: playbook.yml
in playbook. The output I expected is
---
- name: Firewalld check
  hosts: localhost
  become: yes

  tasks:
  - name: Allow ICMP traffic
    firewalld:
      rich_rule: rule family='ipv4' source address="172.16.2.114" protocol value="icmp" accept
      permanent: no
      state: enabled
  - name: Allow ICMP traffic
    firewalld:
      rich_rule: rule family='ipv4' source address="172.16.2.115" protocol value="icmp" accept
      permanent: no
      state: enabled
but the outcome which came is
---
- name: Firewalld check
  hosts: localhost
  become: yes

  tasks:
  - name: Allow ICMP traffic
    firewalld:
      rich_rule: rule family='ipv4' source address=" [u'172.16.2.114', u'172.16.2.115'] " protocol value="icmp" accept
      permanent: no
      state: enabled
So could anyone help me to solve this problem please?
Vithushan Rasalingam (3 rep)
Jul 8, 2020, 10:23 AM • Last activity: Jul 8, 2020, 10:58 AM
2 votes
0 answers
31 views
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., ```man $SHELL``` helps to understan...
Code templates are handy and help in finishing codes without error. I am aware that notepad editors like atom provide code templates for
and
loop for bash. Also aware that
pages provide assistance in understanding the syntax. For e.g.,
$SHELL
helps to understand the
and
commands. But, I was wondering if there is a way to bring code templates into a terminal itself rather than using a code editor? This will help us to be more productive. Let me give a use case scenario. For this post to be solved, I wanted to have a
loop and then a
loop encased in that. So if a template for
loop can be generated by some shortcuts in the terminal such that
for i in **type words here**; do 
  
    **type words here** 
  
done
Then I go inside the for loop template and then click another shortcut for the
`
for i in **type words here**; do 
  
    if [ **type words here**]; then
       **type words here**     
    fi

done
Praveen Kumar-M (622 rep)
May 13, 2020, 08:35 AM
0 votes
1 answers
997 views
Uploading sudoers.d file through ansible gives syntax error but opening and saving in vi fixes it
Alright, I know the question title sucks, but it's the same with the situation itself. What I am trying to do is this: 1. Create a file with sudoers configuration locally 2. Use Ansible to ubload that file with the template module 3. Use the validate feature of the template module to make sure the c...
Alright, I know the question title sucks, but it's the same with the situation itself. What I am trying to do is this: 1. Create a file with sudoers configuration locally 2. Use Ansible to ubload that file with the template module 3. Use the validate feature of the template module to make sure the configuration works So far, so good. Now comes the weird part: The validation (validate: 'visudo -cf %s') of that file throws an error. When I comment out the validation line the files gets uploaded, but a manual validation (visudo -cf /etc/sudoers.d/foo_bar) fails also. Opening the file using vi, saving it (:wq) without making any changes and running the validation again succeeds. My current working thesis: WTF?! But it's late and I am tired. If anyone has suggestions please let me know. I will update this question as soon as I have new information and I will clean it up once I zero in on a solution.
Thorian93 (772 rep)
Oct 29, 2019, 09:22 PM • Last activity: Oct 29, 2019, 09:53 PM
0 votes
1 answers
1564 views
What is wrong in this shell script?
It can not generate two temp-files! Why not? Please help!! The input-file has two columns for the file names. But it fails to copy the TWO-files "fn1", "fn2" into "Data1.dat", "Data2.dat" What is wrong here?? ``` #!/bin/bash FF1=$1 while IFS=" " read -r line1 line2; do fn1=$line1 fn2=$line2 cp $fn1...
It can not generate two temp-files! Why not? Please help!! The input-file has two columns for the file names. But it fails to copy the TWO-files "fn1", "fn2" into "Data1.dat", "Data2.dat" What is wrong here??
#!/bin/bash

FF1=$1
while IFS=" " read -r line1  line2; 
do
  fn1=$line1
  fn2=$line2

  cp $fn1   Data1.dat
  cp $fn2   Data2.dat

...other ext-scripts!...

done  < $FF1
` This code failed copying, so as to generate those two temporary data-files! There are STILL the"error-messages for cp-operation lines" Please help to make the two files correctly. Thx.
David (1 rep)
Oct 5, 2019, 03:44 AM • Last activity: Oct 5, 2019, 05:59 AM
3 votes
1 answers
135 views
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][1] grep solution but I find the code there a bit...
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 solution but I find the code there a bit complicated at the moment and would prefer a dedicated utility if there is one.
Arcticooling (1 rep)
Jun 14, 2018, 04:57 AM • Last activity: Jul 16, 2019, 01:22 PM
Showing page 1 of 20 total questions