Rancher error when setting a boolean field with an environment variable - yaml

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

Related

Azure Pipelines - "While parsing a block mapping, did not find expected key" when setting variables

I have a strange problem that I can't seem to get my head around. I am trying to define some variables for use as part of the job that will deploy bicep files via Azure CLI and execute PowerShell tasks.
I get this validation error when I try and execute the pipeline: While parsing a block mapping, did not find expected key
The line that it refers to is: - name: managementResourceDNSPrivateResolverName
On the research that I have done on this problem, it sounds like an indentation problem but on the face of it, it seems to look fine.
jobs:
- job: 'Deploy_Management_Resources'
pool:
vmImage: ${{ parameters.buildAgent }}
variables:
- name: managementResourceDNSPrivateResolverName
value: 'acme-$[ lower(parameters['environmentCode']) ]-$[ lower(variables['resourceLocationShort']) ]-private-dns-resolver'
- name: managementResourceGroupManagement
value: 'acme-infrastructure-rg-management'
- name: managementResourceRouteTableName
value: 'acme-$[ lower(variables['subscriptionCode']) ]-$[ lower(variables['resourceLocationShort']) ]-route-table'
- name: managementResourceVirtualNetworkName
value: 'acme-$[ lower(variables['subscriptionCode']) ]-$[ lower(variables['resourceLocationShort']) ]-vnet-internal-mng'
Thanks!
The error message ...parsing a block mapping, did not find expected key is usually a side-effect of malformed yaml. You'll see if often with variables if you have mixed formats of arrays and property elements
variables: # an array of objects
# variable group reference object
- group: myvariablegroup
# variable template reference object
- template: my-variables.yml
# variable object
- name: myVariable
value: 'value1'
# variable shorthand syntax
myVariable: 'value1' # this fails because it's a property instead of an array element
While it doesn't appear that the sample you've provided is malformed, I am curious about the use of $[ ] which is a runtime expression. The expression $[ lower(parameters['environmentcode']) ] refers to parameters which is are only available at compile time.
Change:
$[ lower(parameters['environmentCode']) ] to ${{ lower(parameters.environmentCode) }}

Error while passing jmeter simple configuration in build.gradle.kts

While trying to pass simple configuration in build.gradle.ktl file for running jmeter gradle. plugin (https://github.com/jmeter-gradle-plugin/jmeter-gradle-plugin/wiki/Getting-Started)
I am trying to pass simple configuration and my build.gradle.kts file looks like below
jmeter {
jmTestFiles = [file("src/test/jmeter/test2.jmx")] //if jmx file is not
in the default location
jmSystemPropertiesFiles= [file("src/test/jmeter/jmeter.properties")]
//to add additional system properties
enableExtendedReports = true //produce Graphical and CSV reports
}
I am encountering following error
Script compilation errors:
Line 7: jmTestFiles = [file("src/test/jmeter/test2.jmx")]
^ Type mismatch: inferred type is Array but (Mutable)List! was expected
Line 7: jmTestFiles = [file("src/test/jmeter/test2.jmx")]
^ Unsupported [Collection literals outside of annotations]
Line 8: jmSystemPropertiesFiles=
[file("src/test/jmeter/jmeter.properties")]
^ Type mismatch: inferred type is Array but (Mutable)List! was expected
Line 8: jmSystemPropertiesFiles=
[file("src/test/jmeter/jmeter.properties")]
^ Unsupported [Collection literals outside of annotations]
4 errors
I figured out the syntax had to be adopted to kotlin format below
jmSystemPropertiesFiles = mutableListOf(file("src/test/jmeter/jmeter.properties"))

Puppet 6 and module puppetlabs/accounts does not create user account in Hiera YAML format

When I run puppet agent --test I have no errors output but the user did not create.
My puppet hira.yaml configuration is:
---
version: 5
datadir: "/etc/puppetlabs/code/environments"
data_hash: yaml_data
hierarchy:
- name: "Per-node data (yaml version)"
path: "%{::environment}/nodes/%{::trusted.certname}.yaml"
- name: "Common YAML hierarchy levels"
paths:
- "defaults/common.yaml"
- "defaults/users.yaml"
users.yaml is:
accounts::user:
joed:
locked: false
comment: System Operator
uid: '1700'
gid: '1700'
groups:
- admin
- sudonopw
sshkeys:
- ssh-rsa ...Hw== sysop+moduledevkey#puppetlabs.com
I use this module
Nothing in Hiera data itself causes anything to be applied to target nodes. Some kind of declaration is required in a manifest somewhere or in the output of an external node classifier script. Moreover, the puppetlabs/accounts module provides only defined types, not classes. You can store defined-type data in Hiera and read it back, but automated parameter binding via Hiera applies only to classes, not defined types.
In short, then, no user is created (and no error is reported) because no relevant resources are declared into the target node's catalog. You haven't given Puppet anything to do.
If you want to apply the stored user data presented to your nodes, you would want something along these lines:
$user_data = lookup('accounts::user', Hash[String,Hash], 'hash', {})
$user_data.each |$user,$props| {
accounts::user { $user: * => $props }
}
That would go into the node block matched to your target node, or, better, into a class that is declared by that node block or an equivalent. It's fairly complicated for so few lines, but in brief:
the lookup function looks up key 'accounts::user' in your Hiera data
performing a hash merge of results appearing at different levels of the hierarchy
expecting the result to be a hash with string keys and hash values
and defaulting to an empty hash if no results are found;
the mappings in the result hash are iterated, and for each one, an instance of the accounts::user defined type is declared
using the (outer) hash key as the user name,
and the value associated with that key as a mapping from parameter names to parameter values.
There are a few problems here.
You are missing a line in your hiera.yaml namely the defaults key. It should be:
---
version: 5
defaults: ## add this line
datadir: "/etc/puppetlabs/code/environments"
data_hash: yaml_data
hierarchy:
- name: "Per-node data (yaml version)"
path: "%{::environment}/nodes/%{::trusted.certname}.yaml"
- name: "Common YAML hierarchy levels"
paths:
- "defaults/common.yaml"
- "defaults/users.yaml"
I detected that using the puppet-syntax gem (included if you use PDK, which is recommended):
▶ bundle exec rake validate
Syntax OK
---> syntax:manifests
---> syntax:templates
---> syntax:hiera:yaml
ERROR: Failed to parse hiera.yaml: (hiera.yaml): mapping values are not allowed in this context at line 3 column 10
Also, in addition to what John mentioned, the simplest class to read in your data would be this:
class test (Hash[String,Hash] $users) {
create_resources(accounts::user, $users)
}
Or if you want to avoid using create_resources*:
class test (Hash[String,Hash] $users) {
$users.each |$user,$props| {
accounts::user { $user: * => $props }
}
}
Note that I have relied on the Automatic Parameter Lookup feature for that. See the link below.
Then, in your Hiera data, you would have a key named test::users to correspond (class name "test", key name "users"):
---
test::users: ## Note that this line changed.
joed:
locked: false
comment: System Operator
uid: '1700'
gid: '1700'
groups:
- admin
- sudonopw
sshkeys:
- ssh-rsa ...Hw== sysop+moduledevkey#puppetlabs.com
Use of automatic parameter lookup is generally the more idiomatic way of writing Puppet code compared to calling the lookup function explicitly.
For more info:
PDK
Automatic Parameter Lookup
create_resources
(*Note that create_resources is "controversial". Many in the Puppet community prefer not to use it.)

How to use local variable of whitespace array in chef template resource

I am trying to use whitespace arrays in chef template, like below and when I run the chef-client to execute the recipe getting an error saying: option variables must be a kind of [Hash]! below is recipe file
abc = node['abc']
def1 = node['def']
abc_sit = abc['sit']
def_sit = def1['sit']
%w{abc_sit def_sit}.each do | client |
template "/etc/#{client}.sh" do
source 'tunnel.erb'
owner 'root'
group 'root'
variables ("#{client}") --> At this line I am getting error
end
end
The error I am getting when I run the chef-client:
option variables must be a kind of [Hash]! You passed "abc_sit"
As it says, you have to pass in a Hash. Perhaps something like variables myclient: client and then <%= #myclient %> in the template.

yaml syntax error when defining variables using WHEN

I defined these in defaults/main.yml:
- mode : production
- consul_server_address :192.168.1.5
when : mode == "production"
- consul_server_address :192.168.2.5
when : mode == "staging"
but I got:
The offending line appears to be:
- consul_server_address : 192.168.1.5
when : mode == "production"
^ here
When I add a space after colons on consul_server_address, the error changes to:
ERROR! The default/main.yml file for role 'dnsmasq' must contain a dictionary of
variables
I spent some time on yaml syntax but I think this idea is wrong and I should do using another ansible-playbook solution.
You start your YAML with:
- mode : production
- denotes a sequence item, so this line defines that the root element of your YAML document is a sequence. Another sequence item follows:
- consul_server_address : 192.168.1.5
But now, there is a line which is not a sequence item:
when : mode == "production"
This is invalid because we are at indentation level 0, which contains the root element, which is a sequence, which may only contain sequence items. But when : … is a mapping key and therefor illegal here.
What you probably want to do is this:
- mode : production
- consul_server_address : 192.168.1.5
when : mode == "production"
- consul_server_address : 192.168.2.5
when : mode == "staging"
By properly indenting the when lines, they are keys of the mapping contained in the sequence item.
Someone on Ansible's IRC channel suggested me to use groupvars/hostvars for this purpose.
I edited my hosts inventory file and did something like this:
[nginx-staging]
IP_ADDRESS OR FQDN
[nginx-staging:vars]
...
consul_server_address=192.168.2.5
[nginx-production]
IP_ADDRESS OR FQDN
[nginx-production:vars]
...
consul_server_address=192.168.1.5
and it worked for me with a simpler and more straight forward solution.

Resources