![创建多个 AWS Lightsail 实例时,是否可以在 userData 中获取 instanceName?](https://linux22.com/image/711162/%E5%88%9B%E5%BB%BA%E5%A4%9A%E4%B8%AA%20AWS%20Lightsail%20%E5%AE%9E%E4%BE%8B%E6%97%B6%EF%BC%8C%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%9C%A8%20userData%20%E4%B8%AD%E8%8E%B7%E5%8F%96%20instanceName%EF%BC%9F.png)
我使用python apiboto3
来管理Lightsail实例的创建,并将创建的节点链接到salt-master,以下是部分代码:
boot_script='''
curl -L https://bootstrap.saltstack.com -o install_salt.sh
sh install_salt.sh -P
sed -i 's/#master: salt/master: salt.my-domain.com/' /etc/salt/minion
rm -f /etc/salt/minion_id
'''
def main(args):
client = boto3.client('lightsail')
client.create_instances(
instanceNames=[
'test-01',
'test-02',
'test-03',
],
availabilityZone='eu-west-2a',
blueprintId='amazon_linux_2017_03_1_1',
bundleId='nano_1_0',
userData=boot_script,
keyPairName='salt_master'
)
那么,如何通过 userData 将 hostname 设置为其 instanceName 的值?或者还有其他解决方案吗?
谢谢。