用于检索 instanceProfileArn 的 Puppet Facts
Puppet Facts to retrieve instanceProfileArn
我正在编写一个需要传递实例配置文件 arn 的脚本。我一直在使用 puppet 来使用其 facter 功能检索一些信息。下面是一个在网上找到的 facter 输出的(片段)示例,完整的输出可以在这里找到(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]
。什么
然后传递到木偶清单中的语法是正确的吗?
有一个function called parsejson
in the Puppet Forge stdlib
module。它可用于将包含 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
[...]
我正在编写一个需要传递实例配置文件 arn 的脚本。我一直在使用 puppet 来使用其 facter 功能检索一些信息。下面是一个在网上找到的 facter 输出的(片段)示例,完整的输出可以在这里找到(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]
。什么 然后传递到木偶清单中的语法是正确的吗?
有一个function called parsejson
in the Puppet Forge stdlib
module。它可用于将包含 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
[...]