[英]Puppet Facts to retrieve instanceProfileArn
I am working on a script that would require passing the Instance profile arn.我正在编写一个需要传递实例配置文件 arn 的脚本。 I have been using puppet to retrieve some information using its facter capability.
我一直在使用 puppet 使用它的因子功能来检索一些信息。 Below is an (snippet)example of a facter output found online, the full output can be found here ( https://gist.github.com/cliff-wakefield/b232ef51799908a0264eb7e95af09092 ).
下面是在线找到的因子输出的(片段)示例,完整输出可以在这里找到( https://gist.github.com/cliff-wakefield/b232ef51799908a0264eb7e95af09092 )。 What I'd like to obtain is the "InstanceProfileArn"
我想获得的是“InstanceProfileArn”
ec2_metadata => {
ami-id => "ami-34281c57",
ami-launch-index => "0",
ami-manifest-path => "(unknown)",
block-device-mapping => {
ami => "/dev/sda1",
root => "/dev/sda1"
},
hostname => "ip-10-180-0-40.ap-southeast-2.compute.internal",
iam => {
info => "{
"Code" : "Success",
"LastUpdated" : "2016-08-28T23:12:36Z",
"InstanceProfileArn" : "arn:aws:iam::750105279227:instance-profile/AnexPrereqs-AnexIAMInstanceProfile-11O8QJAS4XO7S",
"InstanceProfileId" : "AIPAI6YKKPRVVX2XD6LCK"
}"
By running facter ec2_metadata.iam.info
, I get:通过运行
facter ec2_metadata.iam.info
,我得到:
{
"Code" : "Success",
"LastUpdated" : "2016-08-28T23:12:36Z",
"InstanceProfileArn" : "arn:aws:iam::750105279227:instance-profile/AnexPrereqs-AnexIAMInstanceProfile-11O8QJAS4XO7S",
"InstanceProfileId" : "AIPAI6YKKPRVVX2XD6LCK"
}
However, I am struggling to get the "InstanceProfileArn" printed on the console.但是,我正在努力在控制台上打印“InstanceProfileArn”。
So, two things I want to be able to achieve:因此,我希望能够实现两件事:
facter ec2_metadata.iam.info.<InstanceProfileArn>
from within my instance, I want to be able to see instance profile arn printed in the console.facter ec2_metadata.iam.info.<InstanceProfileArn>
,我希望能够在控制台中看到打印的实例配置文件 arn。$facts[ec2_metadata][iam][info][InstanceProfileArn]
.$facts[ec2_metadata][iam][info][InstanceProfileArn]
。 What would be the correct syntax to then be passed into puppet manifest?There is a function called parsejson
in the Puppet Forge stdlib
module . Puppet Forge
stdlib
模块中有一个名为parsejson
的函数。 It can be used to parse a string containing JSON into a Puppet hash.它可用于将包含 JSON 的字符串解析为 Puppet 哈希。 An example using your data:
使用您的数据的示例:
$ cat Puppetfile
forge "https://forgeapi.puppetlabs.com"
mod "puppetlabs-stdlib", "4.25.1"
$ r10k puppetfile install
$ cat foo.pp
include stdlib
# should be $info_json = $facts[ec2_metadata][iam][info], but for this example
# we'll use a literal...
$info_json = @(INFO)
{
"Code" : "Success",
"LastUpdated" : "2016-08-28T23:12:36Z",
"InstanceProfileArn" : "arn:aws:iam::750105279227:instance-profile/AnexPrereqs-AnexIAMInstanceProfile-11O8QJAS4XO7S",
"InstanceProfileId" : "AIPAI6YKKPRVVX2XD6LCK"
}
INFO
$info = parsejson($info_json)
$instance_profile_arn = $info['InstanceProfileArn']
notice($instance_profile_arn)
$ puppet apply --modulepath=modules foo.pp
Notice: Scope(Class[main]): arn:aws:iam::750105279227:instance-profile/AnexPrereqs-AnexIAMInstanceProfile-11O8QJAS4XO7S
[...]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.