Bumping up against Bicep documentation as usual. I can't seem to find any help on how to add parameters to a Job Schedule for an Automation Account Runbook.
Example from MS is
name: 'string'
parent: resourceSymbolicName
properties: {
parameters: {}
runbook: {
name: 'string'
}
runOn: 'string'
schedule: {
name: 'string'
}
}
}
But when i try -
parameters:{
Param1: 'myval'
Param2: 'myval2'
}
It doesnt get added to the job schedule at all. It's also frustrating that they don't have a JSON view of the Job Schedule section so you can click-ops it and add parameters and then check the file to see the structure. Anyone come across this?
I gave it a try using api-version 2022-08-08 and I had to add extra double quotes for the parameter values:
parameters:{
Param1: '"myval"'
Param2: '"myval2"'
}
I using Analytics Engine on IBM Cloud and trying to pass Ambari configuration Like below in Advanced provisioning options.
{
"ambari_config": {
"hardware_config": "default",
"software_package": "ae-1.2-hive-spark",
"num_compute_nodes": 1,
"advanced_options": {
"ambari_config": {
"spark2-defaults": {
"spark.dynamicAllocation.minExecutors": 1,
"spark.shuffle.service.enabled": true,
"spark.dynamicAllocation.maxExecutors": 2,
"spark.dynamicAllocation.enabled": true
}
}
}
}
}
I am following this documentation to pass the above configuration
https://cloud.ibm.com/docs/services/AnalyticsEngine?topic=AnalyticsEngine-advanced-provisioning-options
After multiple retires i see that each time my cluster request is failing.
After reviewing my request, I figured out that I am passing ambari_config attribute twice for my request which i not accepted
Valid json which worked for me looks like this
{
"hardware_config": "default",
"software_package": "ae-1.2-hive-spark",
"num_compute_nodes": 1,
"advanced_options": {
"ambari_config": {
"spark2-defaults": {
"spark.dynamicAllocation.minExecutors": 1,
"spark.shuffle.service.enabled": true,
"spark.dynamicAllocation.maxExecutors": 2,
"spark.dynamicAllocation.enabled": true
}
}
}
}
one more scenario where cluster creation can fail is like InvalidTopologyException: The following config types are not defined in the stack: [spar2-hive-site-override]
Above issue was because of TYPO to define config property file where user want to add or modify properties.
How I can add Bindings in a "IIS web app manage" task using yaml?
I tried putting the bindings like classic pipeline and doesnt work
The accepted answer doesn't give a great example on usage. The Bindings input accepts a multiline string formatted as a particular JSON object. Also be sure to set AddBinding: true as it appears it will ignore the Bindings input without it.
On a related note, if you are storing your certificates in WebHosting (as opposed to MY), the deployment will fail as the task won't be able to find your certificate. Here's the relevant github enhancement to fix this
task: IISWebAppManagementOnMachineGroup#0
displayName: 'IIS Web App Manage'
inputs:
IISDeploymentType: 'IISWebsite'
ActionIISWebsite: 'CreateOrUpdateWebsite'
...
AddBinding: true
Bindings: |
{
bindings:[
{
"protocol":"http",
"ipAddress":"*",
"hostname":"mywebsite.com",
"port":"80",
"sslThumbprint":"",
"sniFlag":false
},
{
"protocol":"https",
"ipAddress":"*",
"hostname":"mywebsite.com",
"port":"443",
"sslThumbprint":"...",
"sniFlag":true
}
]
}
You need to create a JSon with all information like this:
{
"bindings":[{
"protocol":"http",
"ipAddress":"*",
"port":"xxxxx",
"sslThumbprint":"",
"sniFlag":false
},
{
"protocol":"http",
"ipAddress":"*",
"hostname":"yyyyyy.com",
"port":"80",
"sslThumbprint":"",
"sniFlag":false
},
{
"protocol":"http",
"ipAddress":"*",
"hostname":"xxxxxxxx.com",
"port":"80",
"sslThumbprint":"",
"sniFlag":false
}
]
}
i need to execute the jenkinsfile different behaviors, like suppose:
if the build will trigger manually jenkinsfile executes till build
stage and
if the build trigger by change scm/timer then need to
execute all the stages.
I am a new to Jenkins file(groovy script) so could anyone please help me where and how i can apply condition in Jenkins file. please give me an example for the same with the condition
Jenkinsfile:
pipeline{
agent any
stage('Checkout'){
checkout(scm)
}
stage('build'){
echo "build is success"
}
stage('deploy'){
echo " deployment successfully completed "
}
stage('email notify'){
emailext attachLog: true, body: 'job $job has been triggered', compressLog: true, subject: 'Email notification', to: 'mail id'
}
}
You can use the when directive: https://jenkins.io/doc/book/pipeline/syntax/#when .
Paired up with something like this: currentBuild.rawBuild.getCauses()[0].toString().contains('UserIdCause'), a stage will run whether or not (you decide) if this evaluates to true
This should work:
when {
expression { return currentBuild.rawBuild.getCauses()[0].toString().contains('UserIdCause') }
}
You also have the following from the syntax documentation:
when {
triggeredBy "TimerTrigger"
}
In Cloudformation I have two stacks (one nested).
Nested stack "ec2-setup":
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Parameters" : {
// (...) some parameters here
"userData" : {
"Description" : "user data to be passed to instance",
"Type" : "String",
"Default": ""
}
},
"Resources" : {
"EC2Instance" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"UserData" : { "Ref" : "userData" },
// (...) some other properties here
}
}
},
// (...)
}
Now in my main template I want to refer to nested template presented above and pass a bash script using the userData parameter. Additionally I do not want to inline the content of user data script because I want to reuse it for few ec2 instances (so I do not want to duplicate the script each time I declare ec2 instance in my main template).
I tried to achieve this by setting the content of the script as a default value of a parameter:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters" : {
"myUserData": {
"Type": "String",
"Default" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash \n",
"yum update -y \n",
"# Install the files and packages from the metadata\n",
"echo 'tralala' > /tmp/hahaha"
]]}}
}
},
(...)
"myEc2": {
"Type": "AWS::CloudFormation::Stack",
"Properties": {
"TemplateURL": "s3://path/to/ec2-setup.json",
"TimeoutInMinutes": "10",
"Parameters": {
// (...)
"userData" : { "Ref" : "myUserData" }
}
But I get following error while trying to launch stack:
"Template validation error: Template format error: Every Default
member must be a string."
The error seems to be caused by the fact that the declaration { Fn::Base64 (...) } is an object - not a string (although it results in returning base64 encoded string).
All works ok, if I paste my script directly into to the parameters section (as inline script) when calling my nested template (instead of reffering to string set as parameter):
"myEc2": {
"Type": "AWS::CloudFormation::Stack",
"Properties": {
"TemplateURL": "s3://path/to/ec2-setup.json",
"TimeoutInMinutes": "10",
"Parameters": {
// (...)
"userData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash \n",
"yum update -y \n",
"# Install the files and packages from the metadata\n",
"echo 'tralala' > /tmp/hahaha"
]]}}
}
but I want to keep the content of userData script in a parameter/variable to be able to reuse it.
Any chance to reuse such a bash script without a need to copy/paste it each time?
Here are a few options on how to reuse a bash script in user-data for multiple EC2 instances defined through CloudFormation:
1. Set default parameter as string
Your original attempted solution should work, with a minor tweak: you must declare the default parameter as a string, as follows (using YAML instead of JSON makes it possible/easier to declare a multi-line string inline):
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
myUserData:
Type: String
Default: |
#!/bin/bash
yum update -y
# Install the files and packages from the metadata
echo 'tralala' > /tmp/hahaha
(...)
Resources:
myEc2:
Type: AWS::CloudFormation::Stack
Properties
TemplateURL: "s3://path/to/ec2-setup.yml"
TimeoutInMinutes: 10
Parameters:
# (...)
userData: !Ref myUserData
Then, in your nested stack, apply any required intrinsic functions (Fn::Base64, as well as Fn::Sub which is quite helpful if you need to apply any Ref or Fn::GetAtt functions within your user-data script) within the EC2 instance's resource properties:
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
# (...) some parameters here
userData:
Description: user data to be passed to instance
Type: String
Default: ""
Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
UserData:
"Fn::Base64":
"Fn::Sub": !Ref userData
# (...) some other properties here
# (...)
2. Upload script to S3
You can upload your single Bash script to an S3 bucket, then invoke the script by adding a minimal user-data script in each EC2 instance in your template:
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
# (...) some parameters here
ScriptBucket:
Description: S3 bucket containing user-data script
Type: String
ScriptKey:
Description: S3 object key containing user-data script
Type: String
Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
UserData:
"Fn::Base64":
"Fn::Sub": |
#!/bin/bash
aws s3 cp s3://${ScriptBucket}/${ScriptKey} - | bash -s
# (...) some other properties here
# (...)
3. Use preprocessor to inline script from single source
Finally, you can use a template-preprocessor tool like troposphere or your own to 'generate' verbose CloudFormation-executable templates from more compact/expressive source files. This approach will allow you to eliminate duplication in your source files - although the templates will contain 'duplicate' user-data scripts, this will only occur in the generated templates, so should not pose a problem.
You'll have to look outside the template to provide the same user data to multiple templates. A common approach here would be to abstract your template one step further, or "template the template". Use the same method to create both templates, and you'll keep them both DRY.
I'm a huge fan of cloudformation and use it to create most all my resources, especially for production-bound uses. But as powerful as it is, it isn't quite turn-key. In addition to creating the template, you'll also have to call the coudformation API to create the stack, and provide a stack name and parameters. Thus, automation around the use of cloudformation is a necessary part of a complete solution. This automation can be simplistic ( bash script, for example ) or sophisticated. I've taken to using ansible's cloudformation module to automate "around" the template, be it creating a template for the template with Jinja, or just providing different sets of parameters to the same reusable template, or doing discovery before the stack is created; whatever ancillary operations are necessary. Some folks really like troposphere for this purpose - if you're a pythonic thinker you might find it to be a good fit. Once you have automation of any kind handling the stack creation, you'll find it's easy to add steps to make the template itself more dynamic, or assemble multiple stacks from reusable components.
At work we use cloudformation quite a bit and are tending these days to prefer a compositional approach, where we define the shared components of the templates we use, and then compose the actual templates from components.
the other option would be to merge the two stacks, using conditionals to control the inclusion of the defined resources in any particular stack created from the template. This works OK in simple cases, but the combinatorial complexity of all those conditions tends to make this a difficult solution in the long run, unless the differences are really simple.
Actually I found one more solution than already mentioned. This solution on the one hand is a little "hackish", but on the other hand I found it to be really useful for "bash script" use case (and also for other parameters).
The idea is to create an extra stack - "parameters stack" - which will output the values. Since outputs of a stack are not limited to String (as it is for default values) we can define entire base64 encoded script as a single output from a stack.
The drawback is that every stack needs to define at least one resource, so our parameters stack also needs to define at least one resource. The solution for this issue is either to define the parameters in another template which already defines existing resource, or create a "fake resource" which will never be created becasue of a Condition which will never be satisified.
Here I present the solution with fake resource. First we create our new paramaters-stack.json as follows:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Outputs/returns parameter values",
"Conditions" : {
"alwaysFalseCondition" : {"Fn::Equals" : ["aaaaaaaaaa", "bbbbbbbbbb"]}
},
"Resources": {
"FakeResource" : {
"Type" : "AWS::EC2::EIPAssociation",
"Condition" : "alwaysFalseCondition",
"Properties" : {
"AllocationId" : { "Ref": "AWS::NoValue" },
"NetworkInterfaceId" : { "Ref": "AWS::NoValue" }
}
}
},
"Outputs": {
"ec2InitScript": {
"Value":
{ "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash \n",
"yum update -y \n",
"# Install the files and packages from the metadata\n",
"echo 'tralala' > /tmp/hahaha"
]]}}
}
}
}
Now in the main template we first declare our paramters stack and later we refer to the output from that parameters stack:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"myParameters": {
"Type": "AWS::CloudFormation::Stack",
"Properties": {
"TemplateURL": "s3://path/to/paramaters-stack.json",
"TimeoutInMinutes": "10"
}
},
"myEc2": {
"Type": "AWS::CloudFormation::Stack",
"Properties": {
"TemplateURL": "s3://path/to/ec2-setup.json",
"TimeoutInMinutes": "10",
"Parameters": {
// (...)
"userData" : {"Fn::GetAtt": [ "myParameters", "Outputs.ec2InitScript" ]}
}
}
}
}
Please note that one can create up to 60 outputs in one stack file, so it is possible to define 60 variables/paramaters per single stack file using this technique.