I use python api boto3
to manage the creation of Lightsail instance, and link the nodes created to salt-master, here is part of the code:
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'
)
So, how can I set hostname with the value of its instanceName via userData? Or is there some other solution?
Thanks.