[英]Puppet Facts to retrieve instanceProfileArn
我正在编写一个需要传递实例配置文件 arn 的脚本。 我一直在使用 puppet 使用它的因子功能来检索一些信息。 下面是在线找到的因子输出的(片段)示例,完整输出可以在这里找到( https://gist.github.com/cliff-wakefield/b232ef51799908a0264eb7e95af09092 )。 我想获得的是“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"
}"
通过运行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"
}
但是,我正在努力在控制台上打印“InstanceProfileArn”。
因此,我希望能够实现两件事:
facter ec2_metadata.iam.info.<InstanceProfileArn>
,我希望能够在控制台中看到打印的实例配置文件 arn。$facts[ec2_metadata][iam][info][InstanceProfileArn]
。 然后传递到 puppet manifest 的正确语法是什么? Puppet Forge stdlib
模块中有一个名为parsejson
的函数。 它可用于将包含 JSON 的字符串解析为 Puppet 哈希。 使用您的数据的示例:
$ 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.