在EC2上运行的CentOS上通过Cloud-Init的主机名不起作用

我在CentOS 6.4的EC2实例的用户数据上设置了cloud-config,看起来不适用。

#cloud-config manage_etc_hosts: true preserve_hostname: false hostname: myserver01.example.com 

在云初始化日志,我看到:

 cloud-init[DEBUG]: preserve_hostname is set. not managing hostname 

我该如何强制设置主机名?

我还没有在CentOS 6 AMI上试过这个,但是这对于CentOS 7来说是有效的:

 NEWHOSTNAME="myserver01.example.com" CLOUDTMP=`mktemp $TMPDIR/$(basename $0).XXXXXX 2>/dev/null` || exit 1 cat <<EOF > $CLOUDTMP #!/bin/bash hostnamectl set-hostname $NEWHOSTNAME echo "preserve_hostname: true" > /etc/cloud/cloud.cfg.d/99_hostname.cfg EOF aws ec2 run-instances --user-data file://$CLOUDTMP --cli-input-json file://path/to/file.json