【问题标题】:How to wrtie the following command in userdata cloudformation?如何在 userdata cloudformation 中编写以下命令?
【发布时间】:2019-09-10 01:35:44
【问题描述】:
未从地图中的查找中获取值
UserData: !Base64
'Fn::Join':
- |+
- - '#!/bin/bash'
- !Sub sudo -u $SPLUNK_USER $SPLUNK_BIN init shcluster-config
-mgmt_uri https://$LOCALIP:8089 -replication_port 8090 -replication_factor !FindInMap[SplunkConfig, shcluster-replication-factor, num]
-conf_deploy_fetch_url https://${SplunkSHCDeployer.PrivateIp}:8089 -shcluster_label SplunkSHC
-secret ${SplunkClusterSecret} -auth admin:${SplunkAdminPassword}
【问题讨论】:
标签:
yaml
amazon-cloudformation
【解决方案1】:
使用Sub 而不是Join 会更好。
对于!FindInMap[SplunkConfig, shcluster-replication-factor, num],您需要将其指定为Sub 的参数。
你可能会有类似的东西:
UserData: !Base64
'Fn::Sub':
- |
Content-Type: multipart/mixed; boundary="==BOUNDARY=="
MIME-Version: 1.0
--==BOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"
#!/bin/bash
sudo -u $SPLUNK_USER $SPLUNK_BIN init shcluster-config -mgmt_uri https://$LOCALIP:8089 -replication_port 8090 -replication_factor ${ReplicationFactor} -conf_deploy_fetch_url https://${SplunkSHCDeployer.PrivateIp}:8089 -shcluster_label SplunkSHC -secret ${SplunkClusterSecret} -auth admin:${SplunkAdminPassword}
--==BOUNDARY==--
- ReplicationFactor: !FindInMap[SplunkConfig, shcluster-replication-factor, num]
【解决方案2】:
UserData: !Base64
'Fn::Join':
- |+
- - '#!/bin/bash'
- !Join
- - export $a=
- !FindInMap[SplunkConfig, shcluster-replication-factor, num]
- !Sub sudo -u $SPLUNK_USER $SPLUNK_BIN init shcluster-config
-mgmt_uri https://$LOCALIP:8089 -replication_port 8090 -replication_factor $a
-conf_deploy_fetch_url https://${SplunkSHCDeployer.PrivateIp}:8089 -shcluster_label SplunkSHC
-secret ${SplunkClusterSecret} -auth admin:${SplunkAdminPassword}
这对我有用。