YAML - Get data on a new yaml attribute - yaml

I have a YAML file with this data:
TEST:
1: 10
2: 15
and I added new data, and I want to make data of this attribute with the same data of TEST attribute. EX
TEST2:
1: data of the first element of TEST
Is there any solution ?

The solution (after searches):
TEST:
1: &first_test 10
2: 15
TEST2:
1: *first_test

Related

Including property lists in SpringBootTest properties attribute

So I've found that SpringBootTest allows injection of properties into test files so that the data in the test file can be overwritten so that production data in the properties file such as:
properties file
data.test1 = Production data 1
data.test2 = Production data 2
Can be overwritten with test data in the test file such as:
test file
#SpringBootTest(properties = {
"data.test1=Test data 1",
"data.test2=Test data 2"})
My issue is that I have lists in my properties file. Is there any way I can inject a list into the SpringBootTest properties attribute like the data below?
properties file with list
data-list:
- id: 1
data: Prod data 1
other-data: Other prod data 1
- id: 2
data: Prod data 2
other-data: Other prod data 2
there are 2 ways:
1: You can override like this
#SpringBootTest(properties = {
"data-list[0].id=1",
"data-list[0].data=data",
"data-list[0].other-data=data",
"data-list[1].id=1",
"data-list[1].data=data",
"data-list[1].other-data=data"})
2: under test folder create a resources folder and override application.properties or yaml file , Spring boot test wil pick overdried file instead of your main app file

Rancher error when setting a boolean field with an environment variable

I have a rancher-compose.yml file where I set the upgrade_strategy.start_first field using an environment variable like this:
upgrade_strategy:
start_first: ${START_FIRST}
batch_size: 1
When running using the rancher-compose CLI, I get the following error:
ERRO[0000] Failed to open project origami-svcproxy: yaml: unmarshal errors:
line 28: cannot unmarshal !!str `false` into bool
When running in debug I see the following yaml:
upgrade_strategy:
batch_size: 1
start_first: "false" # <-- notice the surrounding quotes, missing from the rest of the variable replacements
How can I set this field dynamically?
I had the same problem and used a different strategy to fix the issue. First step is to convert docker-compose.yml to a template, docker-compose.yml.tpl. Second, use template logic to fetch the value of the boolean variable.
upgrade_strategy:
start_first: {{ .Values.START_FIRST }}
batch_size: 1
Reference: https://github.com/rancher/rancher-catalog/blob/v1.6-development/infra-templates/ipsec/9/docker-compose.yml.tpl#L21

shell script : how to merge 2 files asymmetrically [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have 2 files that I need to merge in order to create a report summary, as shown in the example below:
file 1 contains workflow names:
Workflow_name.log
---------------------------------------------
workflow Wf_s_m_DAI_IFDS_Account_Stage
workflow Wf_s_m_DAI_IFDS_Txn_Map
file 2 contains matching workflow-run summaries - that is, the nth summary block corresponds to the nth line in the names file:
*************** Summary ***************
Objects provided for validation: 10
Objects skipped: 7
Objects that were invalid before the validation: 0
Objects successfully validated: 3
Objects that are still invalid after the validation: 0
Validated objects that were Saved/Checked in: 0
Cannot save objects due to lock conflict: 0
*************** Summary ***************
Objects provided for validation: 14
Objects skipped: 11
Objects that were invalid before the validation: 0
Objects successfully validated: 3
Objects that are still invalid after the validation: 0
Validated objects that were Saved/Checked in: 0
Cannot save objects due to lock conflict: 0
validate completed successfully.
Expected output after merging the files:
workflow Wf_s_m_DAI_IFDS_Account_Stage
*************** Summary ***************
Objects provided for validation: 10
Objects skipped: 7
Objects that were invalid before the validation: 0
Objects successfully validated: 3
Objects that are still invalid after the validation: 0
Validated objects that were Saved/Checked in: 0
Cannot save objects due to lock conflict: 0
workflow Wf_s_m_DAI_IFDS_Txn_Map
*************** Summary ***************
Objects provided for validation: 14
Objects skipped: 11
Objects that were invalid before the validation: 0
Objects successfully validated: 3
Objects that are still invalid after the validation: 0
Validated objects that were Saved/Checked in: 0
Cannot save objects due to lock conflict: 0
validate completed successfully.
Please let me know the right approach to getting the desired output.
Thanks in advance.
Ahshan
An awk solution with getline:
Let's assume file f1 contains the workflow names and f2 the summaries:
awk -v namesFile=f1 '
$0 == "*************** Summary ***************" {
getline name < namesFile # read next name from names file
print name # print name
}
1 # print each input line
' f2
The opening { must be on the SAME line as the pattern ($0 == "...") in order for the block to be associated with it.
1 is (effectively) shorthand for {print}; i.e. it simply outputs the line.
Note that there's no error handling - the number of names is expected to match the number of summary blocks.

Access alias properties in Ebean when loading initial test data in Play

I'm loading initial test data for my models in Play 2.1.
I would like to access the String property "question" of Question Model.
Here is my initial-data.yml file:
- &q1 !!models.Question
id: 001
question: Sample question?
- &mem1 !!models.Member
id: 001
memberName: Test
!!models.SecurityQuestion
member: *mem1
question: *q1.question
answer: sample answer
But all I get is the following error:
Test models.ModelsTest.fullTest failed: while scanning an alias; expected alphabetic or numeric character, but found .
How do I access the properties of an alias?
What about this:
questions:
- !!models.Question
id: 001
question: Sample question?
members:
- !!models.Member
id: 001
memberName: Test
security:
!!models.SecurityQuestion
member: !!models.Member
id: 001
question: !!models.Question
id: 001
answer: sample answer

Mapping many-to-one in YAML

I'm trying to introduce a many-to-one kind of mapping inside a YAML configuration file for rake.
That is, I have something like:
- server: address
and I'd like to have something like:
- server: {1, 3, 5: address1; 2, 8, 12: address2}
of course, this is not the correct syntax.
This because I need a different address according to a given ID.
CONFIG['server'][3] # this should return 'address1'
CONFIG['server'][5] # this should return 'address1' too
CONFIG['server'][12] # and this should return 'address2'
Is this feasibile in some way?
Thank you in advance
It should work this way:
create a file in config called server_config.yml:
common: &common
common_stuff_foo: foo
common_stuff_bar: bar
server:
1:
<<: *common
adress: adress_for_server1
2:
<<: *common
adress: adress_for_server2
... #some other servers
12:
<<: *common
adress: adress_for_server12
put a file to config/initializers like config_servers.rb with the content
CONFIG = YAML.load_file("#{RAILS_ROOT}/config/server_config.yml")
and you might get your address via
CONFIG['server'][1]['address'] in your application
It's not tested, but I think it will work. I'm just a little bit uncertain about those numbers in the yaml-file

Resources