我試圖建立打包機和ansible-remote來創建基於我的預先存在的可執行腳本的AMI。我碰到兩個問題之一。Packer和Ansible SSH/Sudo
首先我遇到了SSH問題,我收到了SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh
。我在我的配置文件中添加了connection: local
,似乎已經解決了這個問題。
現在我遇到來自Ansible的問題sudo: a password is required
。我不清楚爲什麼我指定的用戶使用NOPASSWD訪問sudo,並且我已通過使用包裝員使用臨時密鑰的設置進行連接來驗證這一點。我收到以下錯誤,並嘗試通過ansible_become_user
和ansible_become_pass
作爲變量通過封隔器運氣不佳。這似乎也許它試圖sudo對我的本地連接,但需要密碼?任何想法如何正確設置。
帕克:
{
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"subnet_id": "subnet-56343453",
"source_ami": "ami-61bbf104",
"instance_type": "t2.micro",
"ssh_username": "centos",
"ssh_pty" : true,
"ami_name": "packer-example {{timestamp}}"
}],
"provisioners": [
{
"type": "shell",
"inline": ["sudo sed -i 's/requiretty/!requiretty/' /etc/sudoers"]
},
{
"type": "ansible",
"playbook_file": "../config/site/packer.yml",
"user": "centos",
"ansible_env_vars": [ "ansible_become_user=centos", "ansible_become_pass=packer", "ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'" ]
}
]
}
Ansible:
---
- name: run base centos playbooks
hosts: all
connection: local
become: true
roles:
- base_centos7
可能是誤讀這一點,但它顯示爲'連接:local'會在本地運行的劇本,其中'packer'在運行,而不是在供應情況。 –
嘿,你是怎麼解決這個問題的? 我現在在收集事實步驟中遇到了完全相同的錯誤。 數據無法發送到遠程主機127.0.0.1。 我試過連接:本地正如MattW所說的,他是對的。 但沒有它沒有工作 – straykiwi