How to declare and use map var in yaml file? - yaml

I try to write a map in y yaml file and want to use it in yaml file itself with a key. for example ->
in my yaml file I wrote -
pod_env_map:
pod1: "env1"
pod2: "env2"
pod3: "env3"
and in this yaml file itself I'm getting a var $pod_name.
So now i want to write stages with some command for all pod and correspond env.
So instead of putting multiple checks of $pod_name == 'pod1'....
I want to use above dict somehow in code like pod_env_map[$pod_name], please help me to know what should be the syntax for this? I tried to find but didn't get relavent info anywhere.

Related

Create a dynamic path inside a yaml file

I have a yml file that contains a path for data source. Something like this:
data_source: s3://bucket/file.csv
I want to change the job to grab only the file with yesterday appended to the title, for example:
file-2021-10-21.csv
so basically, something like this:
data_source: s3://bucket/file-{yesterday}.csv
How can i define it in the yaml file? thanks!
You can have something like below, where all files defined under 'files' variable
data_source: s3://bucket/file-
files:
- 2021-10-21.csv
- 2021-10-21.csv

How to use environment variable(string) in a .conf file

I have a .conf file that has a label and variable that I'm trying to move to a .env file. How can I accomplish this?
This is what I have in my .conf file
[[inputs.snmp]] #Label
agents = ["1.1.1.1:111","2.2.2.2:111","2.3.3.3:111"] #Variable
version = 2 #Variable
I'm trying to have something like this in the .env file
VAR_FOR_CONF_FILE='[[inputs.snmp]]\n agents= ["1.1.1.1:111","2.2.2.2:111","2.3.3.3:111"]\n version=2'
I was hoping I could use $VAR_FOR_CONF_FILE in my .conf file instead of [[inputs.snmp]]agents = ["1.1.1.1:111","2.2.2.2:111","2.3.3.3:111"]
but I keep getting this error Error parsing data: line 7: invalid TOML syntax for $VAR_FOR_CONF_FILE (Im not sure if I'm getting this error because I have the syntax wrong in my .env file or I'm declaring $VAR_FOR_CONF_FILE incorrectly in my .conf file)
Am I doing it correctly (or is it even possible to do what I'm trying to accomplish)?
(Note: I'm trying to accomplish this so I can simply use $VAR_FOR_CONF_FILE instead of hard coding things in the .conf file)
I'm trying to use VAR_FOR_CONF_FILE in the .conf file
If the .conf file parsing program doesn't support variable substitution, there's no way around modifying the .conf file, but this can be automated:
sed -i "s/\<VAR_FOR_CONF_FILE\>/$VAR_FOR_CONF_FILE/" my.conf

DaCe build files

I am using the DaCe framework in Python and would like to generate SDFGs that take command line arguments. I like the sample file DaCe offers and would like to use it as a base for this. However, arguments of the SDFG are defined at the start of the sample file and overwrites any command-line inputs.
Is there any way I could tell DaCe to make an exception and not redefine those variables when creating the sample file?

How do I pass an array of configurations to a YAML file in Golang?

I am trying to create a YAML configuration file using gosexy/yaml.
I know how to create a YAML file of the following format:
another:
tree:
- 1
I use the code settings.Set("another","tree",[]int{1}) to create the above file.
Now, how can I create a file of the format
another:
- tree: 1
I tried using the code settings.Set("another",[]{yaml.Set("tree",1)}) to create the above file. As it might be obvious, I receive a type error since I am not passing the type to the array.
Am I on the right track? If yes, what should be the type to be passed. If no, what is the alternative way to do this?
the type of tree that you need is []map[string]int
example code:
settings := yaml.New()
settings.Set("another", []map[string]int{{"tree": 1}})
settings.Write("test.yaml")
the result of test.yaml
another:
- tree: 1
hope it help

Curly braces in a YAML file

I've found the following .travis.yml template.
I've noticed this:
repo: {GITHUB_USER}/{PROJECT_NAME}
Is this a special .yml variable syntax I'm not familiar with? Where can I set these values (GITHUB_USER, PROJECT_NAME)?
I know I can use environment variables, like so:
repo: $GITHUB_USER/$PROJECT_NAME
but this syntax looks different.
That is not a valid YAML file. After the first } the YAML parser will expect a block style continuation. This means either a key that aligns with repo or outdenting. Instead it finds a / and any YAML parser should throw an error on that.
This looks like a template for a YAML file, e.g. using something like the following in Python after loading the contents of the file in string templ:
templ.format(**dict(GITHUB_USER="Janez", PROJECT_NAME="test"))
On the other hand the recommended extension for YAML files has been .yaml for many more years than Travis exists, so maybe that is why they used the .yml extension.

Resources