AWS cloud-config 未设置 dns-nameservers

AWS cloud-config not setting dns-nameservers

这是我实例上的 cloud.cfg(我在配置 ami 从中启动实例时手动篡改了它)

root@ip-10-17-0-121:~# cat /etc/cloud/cloud.cfg | grep -i resol -C 3

# Network configuration for ami
manage_resolv_conf: true

resolv_conf:
  nameservers: ['10.11.4.1']

然而,鉴于以下情况,这一点从未被考虑在内:

# cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.17.0.2
search eu-west-1.compute.internal

我尝试过创建和不创建以下文件

# cat /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
network: {config: disabled}

我设法让我的实例获得了我的自定义 dns-nameserver,如下所示

- name: pre_tasks --> Add my custom dns-nameserver
  lineinfile:
   path: /etc/dhcp/dhclient.conf
   regexp: '^#prepend domain-name-servers'
   line: 'prepend domain-name-servers 10.11.4.1;'
  become: yes

但是现在我收到以下警告:

pkara@ip-10-17-0-35:~$ sudo -i
sudo: unable to resolve host ip-10-17-0-35

除非我解决这个问题,否则不接受我的回答;

edit_1:将此添加到我设置为用户数据的 cloud-config.yml 并没有多大帮助:

hostname: localhost
manage_etc_hosts: true

edit_2:将此添加到我的 cloud-config.cfg 帮助我解决了上述 unable to resolve host 问题

bootcmd:
  - echo "127.0.0.1 $(hostname)" >> /etc/hosts