如何配置Packer配方,以便您的配置程序可以在Digital Ocean图像上执行sudo命令?我有以下方法,我正在尝试在远程主机上安装Ansible,以便我可以使用位于我本地管理主机上的Ansible playbook“site.yml”进行配置。问题是配方失败,因为找不到sudo。我不确定Packer的配置命令在哪个帐户上运行,因为在使用Digital Ocean的构建阶段似乎没有办法指定用户帐户的创建。但无论帐户是什么,打包器都找不到sudo,因为这个未知帐户的名称不在sudoers文件中。如果在构建远程计算机的映像时除了无密码的root帐户之外什么都没有,我该如何运行我的配置程序?
谢谢!
包装工配方:
{
"variables": {
"do_api_token": "<my api token>"
},
"builders": [
{
"type": "digitalocean",
"api_token": "{{user `do_api_token`}}",
"image": "debian-8-x64",
"region": "sfo1",
"size": "512mb"
}
],
"provisioners": [
{
"type": "shell",
"inline": [
"sleep 30",
"sudo apt-get update",
"sudo apt-get install -y ansible"
]
},
{
"type": "ansible-local",
"playbook_file": "site.yml",
"inventory_file": "inventory.ini"
}
]
}
包装工错误:
digitalocean output will be in this color
digitalocean: Creating temporary ssh key for droplet...
digitalocean: Creating droplet...
digitalocean: Waiting for droplet to become active...
digitalocean: Waiting for SSH to become available...
digitalocean: Connected to SSH.
digitalocean: Provisioning with shell script: /var/folders/bm/d7bxd26n0md057x36jhbv7280000gn/T/packer-shell79618998.
digitalocean: /tmp/script_7943.sh: 3: /tmp/script_7943.sh: sudo: not found. <= ERROR!!!
digitalocean: Destroying droplet...
digitalocean: Deleting temporary ssh key...
digitalocean' errored: Script exited with non-zero exit status: 12.
==> Some builds didn't complete successfully and had errors:
--> digitalocean: Script exited with non-zero exit status: 127
==> Builds finished but no artifacts were created.
答案 0 :(得分:0)
你确定安装了sudo吗?根据{{3}},
Debian 8没有安装sudo,所以让我们安装它 易于得到。
本文接着详细介绍了如何创建具有sudo权限的新用户,稍后您会发现这些权限很有用,但在短期内,您是否尝试过从您的ansible代码中删除sudo?