Questions tagged [yaml]
YAML is a data serialisation format designed for human readability, supporting data with self references. YAML 1.2 is a superset of JSON, so its tools can be used to process JSON. Use this tag for question that involve features specific to the YAML format.
89
questions
2
votes
1
answer
640
views
replace a value in yaml using yq and sed
I am trying to replace a value for key ipAddress using sed for the below yaml block:
networkInterfaces:
- network:
id: network-1111
ipAddress: 192.168.0.0
The command I tried: sed -i 's/\(....
0
votes
2
answers
210
views
Executing `yq`, but `jq` gets executed
I am very confused.
I installed the Debian package yq
But if I call it, jq gets executed:
root@rescue ~ # echo '{"key": "value"}' | yq -p=json
jq: Unknown option -p=json
Use jq --...
1
vote
2
answers
2k
views
Replace value in yaml file using yq
I am using yq version 4.34.1 in powershell.
I try to replace the value of .spec.source.targetRevision in target.yaml with the newer value from a variable $newTargetRevision. So, what I am doing now is ...
0
votes
1
answer
96
views
yamlfix not using configuration + (neo)vim usage
I'm using yamlfix with ale in vim.
I followed these steps because I wanted to remove the automatic "---" adding on top of the file every time I save my work (and some others default ...
2
votes
2
answers
2k
views
Change value in array using yq from mike farah
In my yaml file I have this persons array (it only has one element always)
persons:
- name: mario
version: 1.0.0
city: Madrid
how can I replace city to any other value using yq ?
0
votes
1
answer
2k
views
Add content to yaml file using yq from mike farah
This is a basic question but I am struggling to make this work as I have no experience in bash.
Lets say I have a directory directory_1 and inside this directory I have cen1.yaml and cen2.yaml. cen1....
-2
votes
3
answers
149
views
sed: -e expression #1, char 101: unterminated `s' command
can someone suggest me what is going wrong here -
sed -i "s|##CONNECTION_DETAILS##|${CONNECTION_DETAILS}|g" dep.yaml.
The value of CONNECTION_DETAILS is in encoded form:
...
0
votes
1
answer
221
views
bash to get required lines from file using sed/awk [closed]
File content as below:
Text1:
text_1: Text1 text_1
text_2:
- text
- file1:\\
- file2:\\
Text2:
text_1: Text2 text_1
text_2:
- text
- file3:\\
Text3:
etc
Output:...
2
votes
2
answers
1k
views
Tool to flatten yaml
Is there a tool to flatten yaml structure like this:
foo:
bar:
baz: true
into this:
foo.bar.baz = true
not sure what is this syntax name
context: I need this for hcl, setting a lot of values ...
0
votes
1
answer
53
views
I encountered an error in the YAML script when using Docker
I am using version: '3.8'
services:
mydb:
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: shiva
mywordpress:
image: wordpress
ports:
- 8080:80
links:
- mydb: ...
0
votes
1
answer
72
views
How to split long commands containing special character into multiline commands?
I have been reading documentation from gitlab at:
https://docs.gitlab.com/ee/ci/yaml/script.html#split-long-commands
In my case I have a special character (colon ':'), so I also did read:
https://...
-1
votes
2
answers
507
views
How do I use yq to change dns severs in a yaml?
Here is my yaml file:
network:
ethernets:
ens160:
addresses:
- 10.200.2.148/22
gateway4: 10.200.0.1
nameservers:
addresses:
- 1.1.1.1
- 2.2.2.2
...
3
votes
2
answers
8k
views
Bash variable substitution into yq command
Given a YAML file, example.yaml:
node:
sub_node:
get_this:
I'd like to get a variable containing get_this using Mike Farah's yq and the string sub_node
yaml="$(cat example.yaml)"
...
0
votes
1
answer
1k
views
Help with yq assignment
I'm trying to use yq to update the static IP on an ubuntu machine via the netcfg yaml file.
My file:
network:
version: 2
renderer: networkd
ethernets:
enp0s1:
dhcp4: no
addresses:...
0
votes
2
answers
331
views
Extract value from broken JSON output in Shell
Once I list the backup files from a server, It throws me the output as follows:
{
"backupFiles": [
"XYZ_Backup_2.0.0.0-417_2022_08_14_12_10.gz",
"...
0
votes
2
answers
5k
views
Set and Test Enviornment Variables in .yaml files in Linux
I have one abc.yml file as below which contains username and password parameters. I have stored these parameters in env variable of my linux user But when application is execting abc.yml file it's not ...
0
votes
1
answer
641
views
How can I match file name and a variable in a YAML file?
I am new to shell scripting. What I exactly want to do is this: There is a YAML file and there are different variables in that file, I need to match a particular variable name with a directory name ...
2
votes
1
answer
137
views
How to add conditional force to the command in ansible playbook?
I want to copy the file forcedly only for projectA item from below playbook.
- name: Populate /usr/local/mywork/ binaries where necessary
copy:
src: "output/here/usr/local/mywork/{{item}}&...
4
votes
5
answers
2k
views
How to use awk to extract a YAML metadata block
I have many Markdown files with a YAML metadata block at the top:
---
title: title of work
author: author name
author-sort: name, author
published: N
date: XXXX-XX-XX
pub-number: XXXXX
embedded-title: ...
-3
votes
2
answers
48
views
am not sure how to write on other file
hi i have this script called script.sh have 2 variable
#! /bin/bash
read -p " name " name
read -p " last " last
( here am not sure what to do but if possible to open file name....
0
votes
0
answers
37
views
Match only first number from exact 'word' and ignore if fail [duplicate]
Currently I have written this to extract numbers from PASS_MAX_DAYS [number]. I want it to ignore if it matches the example.
Example(only bold numbers)
PASS_MAX_DAYS 30
pass_max_days 30
PASS_MAX_DAYS ...
1
vote
1
answer
1k
views
regexp to only extract first set/group of numbers from line of string from a file
How can I use regexp to extract first set/group of numbers from line of string from a file and ignore lines that have two set of numbers, any symbol (except PASS_MAX_DAYS), and have it show on the ...
0
votes
2
answers
2k
views
bash iterate through several directories to build one single yaml file
I have a directory with several folders (only interested in folders one level deep) and each one of these folders have files inside (values.yaml and example.yaml)
folder_1
-values.yaml
-example.yaml
...
1
vote
4
answers
5k
views
Using Bash to iterate through nested directories and extract certain fields from YAML files
I am learning bash and what I need is to iterate through a directory (inside has other directories) and find all files with the name example.yaml.
These files have several key-value pairs (example ...
0
votes
4
answers
418
views
sed vs. awk: Read a file line by line and append to a specific line in another file
Consider two files below users.txt:
Arnold.Bosch
David.Ledru
Mehri.Sunny
and docker-compose.txt:
version: '3.9'
services:
strongswan-server:
image: vpn-strongswan
container_name: strongswan-...
0
votes
3
answers
74
views
Determine IP address and edit the config in single command
I'm trying to determine internal IP of a docker container and use that as an value in an yaml config file.
The command for determining the IP is;
docker inspect -f '{{range.NetworkSettings.Networks}}{{...
0
votes
1
answer
118
views
Need help Formatting a file having key: value [duplicate]
I have a file having the below values:
cat data.txt
server1: 'calv'
server2: 'anot'
log: '/u/log/1'
server3: 'calv'
server4: 'anot'
server5: 'secd'
server6: 'calv'
LIB_TRGT_calv,anot: '/tmp/hello.txt'
...
3
votes
1
answer
2k
views
ignore whitespace at the beginning of a search pattern
This sed expression works, but is there a better way to represent the white space in both the search pattern and replace string?
BRANCHTAG=7.17.9-main-5ee3e99d5ff002862d93728d821461033de1186d
...
0
votes
1
answer
182
views
Convert puppet manifest config to hiera
I installed corosync-pacemaker cluster via puppet. Now I would to like keep my data into hiera file. How should I convert cs_primitive section into yaml file?
cs_primitive { 'nfsshare_fs':
...
3
votes
5
answers
801
views
find duplicate 1st field and concat its values in single line
I have a file that has entries in key: value format like the below:
cat data.txt
name: 'tom'
tom_age: '31'
status_tom_mar: 'yes'
school: 'anne'
fd_year_anne: '1987'
name: 'hmz'
hmz_age: '21'
...
3
votes
2
answers
2k
views
How to extract a few IP addresses from a YAML file
I have this file, and I'd like to select all the IP addresses under the masters/hosts section if their line is not commented. I tried this sed 's/.*\ \([0-9\.]\+\).*/\1/g', but it did not work.
metal:
...
0
votes
2
answers
711
views
sed command to replace pattern including newline pattern with blank
I have a yaml file which include text:
- name: flexvol-driver-host
hostPath:
type: DirectoryOrCreate
path: /usr/libexec/kubernetes/kubelet-plugins/volume/exec
...
1
vote
1
answer
809
views
Parsing YAML to create dynamic queries in shell
I am very new to scripting, and I have been tasked with figuring out a way to script a shell script that will create SQL queries based on a provided YAML document. I could trace down the yq parser to ...
-1
votes
1
answer
279
views
How to replace a pattern permanently in a file using pipe Unix command
I have following lines, so I just want to replace particularly
client_encryption_options:
enabled: true
to
client_encryption_options:
enabled: false
...
1
vote
3
answers
3k
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: {{...
-1
votes
1
answer
52
views
File Comparison
I have two files with FILE1 containing lots of lines and FILE2 with KEY VALUE parms. I need to compare FILE2 with FILE1 and if there is match the corresponding word in FILE1 should be replace with ...
1
vote
1
answer
2k
views
Generate full paths from nested (for example yaml) directory structure
I try to write script in shell/bash that will convert yaml directory structure to full paths (for further mkdir -p it). Yaml is my choice because of human-editability. Structure example is:
- ...
0
votes
3
answers
8k
views
Shell script to find the list of a keys inside a key in Yaml file
I have a yaml file
info:
description: Api
contact:
name: Api
tags:
- name: ""
description: ""
paths:
/data1/1:
post:
tags:
- "tag1"
/...
2
votes
2
answers
9k
views
Modify yaml file in bash without any external dependency
I've multiple configurations in YAML file and I need to change some paramaters using a Bash script. Is it possible? I want to avoid using any external dependency.
My YAML Looks like
%YAML 1.2
---
name:...
-1
votes
2
answers
312
views
Append new webhook to alertmanager config file using shell
I am using alertmanager for notification purpose and by default alertmanager only has one webhook. As per my requirement one more webhook is required.
Existing config
global:
resolve_timeout: 5m
...
0
votes
0
answers
154
views
Can't fold YAML block in Vim after commenting it out
I have a YAML file, and configured the folding of different sections for the document in the Vim editor. However, when I comment out a section, it remains unfolded, and trying to "re-fold" ...
0
votes
1
answer
1k
views
Ansible facts output in one line
I need some information from Ansible facts, hence created below YAML. but its giving error. My requirement is to get the output in one line. So that we can filter it using CSV or spreadsheet.
---
- ...
0
votes
1
answer
911
views
Is it possible to make a YAML use ISO 8601 date format?
I am using a tool called organize in order to sort folders with a lot of stuff in them and was wondering if it was possible to tell it to create, sort, or rename using ISO 8601 date format.
The config ...
6
votes
5
answers
10k
views
How do I remove all specific sub-sections of a specific header in a YAML file?
I'm using bash shell. I have a YAML file from which I want to remove certain blocks of text.
/image-content:
post:
operationId: createEventPublic
summary: Process events
...
0
votes
3
answers
3k
views
Struggling using sed command with variables
So I have the following variables defined in a bash script:
new_commit="back:h3912kk"
old_commit="back:1.0.1"
file = docker-compose.yml
Then I have this yml $file:
version: '...
3
votes
6
answers
1k
views
Passing variable to AWK not working inside a loop
I have this awk statement that reads a YAML file and outputs a particular value. I need to loop this awk inside a loop where I read a key value from a list of values and pass that key to awk.
The YAML ...
0
votes
4
answers
2k
views
How do I get a multiline awk script running in bash
To start this script is running it a Github workflow, using shell bash, yaml truncated for readability. I've tried a number of things to make it work as multiline, so I can have comments.
set -x
...
1
vote
2
answers
1k
views
Using sed to match a dynamic, multi-line string and append to it
I have an Ansible yaml file that I want to append on a new line after state: present in the example matches below with use: package_manager using sed.
# Example 1
- name: Package X Install
package:
...
6
votes
5
answers
3k
views
Replace value in "key: value" statement, but only on first occurence of the key in the file
I have a yml file
spring:
datasource:
url: url
username:test
password: testpwd
api:
security:
username:foo
password: foopwd
I want to update only the first occurrence or ...
0
votes
3
answers
3k
views
Parse yaml file without using outside tool [duplicate]
I am new to bash, dragged into a problem where I need to update some dynamic parameters in a yaml file
Based on query (search4.subsearch1.name), i need to update
name: old_name
into
name: new_name
...