我有一个非常简单的 VagrantFile 和 Ansible Playbook。我只想测试安装httpd。但是每次我vagrant provision
在虚拟机启动后运行时都会收到此错误:
Rons-MacBook-Pro:development you$ vagrant provision
[default] Running provisioner: ansible...
PLAY [Install and start apache] ***********************************************
GATHERING FACTS ***************************************************************
<10.0.0.111> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-1384111346.71-231091208956411 && echo $HOME/.ansible/tmp/ansible-1384111346.71-231091208956411']
<10.0.0.111> REMOTE_MODULE setup
<10.0.0.111> PUT /var/folders/h7/3b23bqhs5g39w_jntlkz3hpm0000gn/T/tmpQ3Hvaw TO /Users/you/.ansible/tmp/ansible-1384111346.71-231091208956411/setup
<10.0.0.111> EXEC ['/bin/sh', '-c', '/usr/bin/python2.6 /Users/you/.ansible/tmp/ansible-1384111346.71-231091208956411/setup; rm -rf /Users/you/.ansible/tmp/ansible-1384111346.71-231091208956411/ >/dev/null 2>&1']
ok: [10.0.0.111]
TASK: [Update apt cache] ******************************************************
<10.0.0.111> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-1384111347.33-79837739787852 && echo $HOME/.ansible/tmp/ansible-1384111347.33-79837739787852']
<10.0.0.111> REMOTE_MODULE apt upgrade=yes update_cache=yes
<10.0.0.111> PUT /var/folders/h7/3b23bqhs5g39w_jntlkz3hpm0000gn/T/tmpr5r1YH TO /Users/you/.ansible/tmp/ansible-1384111347.33-79837739787852/apt
<10.0.0.111> EXEC ['/bin/sh', '-c', '/usr/bin/python2.6 /Users/you/.ansible/tmp/ansible-1384111347.33-79837739787852/apt; rm -rf /Users/you/.ansible/tmp/ansible-1384111347.33-79837739787852/ >/dev/null 2>&1']
failed: [10.0.0.111] => {"failed": true}
msg: Could not import python modules: apt, apt_pkg. Please install python-apt package.
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/you/playbook.retry
10.0.0.111 : ok=1 changed=0 unreachable=0 failed=1
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
这是我的流浪文件:
Vagrant.configure("2") do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "development-precise64"
# config.vm.host_name = "development.somethingwithcomputers.com"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network "private_network", ip: "10.0.0.111"
# Share an additional folder to the guest VM. The first argument is
# an identifier, the second is the path on the guest to mount the
# folder, and the third is the path on the host to the actual folder.
# config.vm.share_folder "v-data", "/vagrant_data", "../data"
config.vm.synced_folder "/Users/rontalman/Public/Dropbox/Development/Code/Webdevelopment/htdocs/mgc.com", "/var/www", id: "vagrant-root", :nfs => false
config.vm.usable_port_range = (2200..2250)
config.vm.provider :virtualbox do |virtualbox|
virtualbox.customize ["modifyvm", :id, "--name", "mgc"]
virtualbox.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
virtualbox.customize ["modifyvm", :id, "--memory", "512"]
virtualbox.customize ["setextradata", :id, "--VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end
# SSH
config.ssh.username = "vagrant"
config.ssh.shell = "bash -l"
config.ssh.keep_alive = true
config.ssh.forward_agent = false
config.ssh.forward_x11 = false
config.vagrant.host = :detect
# Ansible
config.vm.provision "ansible" do |ansible|
ansible.inventory_path = "provisioning/inventory.yml"
ansible.playbook = "provisioning/playbook.yml"
ansible.verbose = "vvvv"
end
end
这是我的简单 playbook.yml:
---
- name: Install and start apache
hosts: all
user: root
tasks:
- name: Update apt cache
apt: upgrade=yes
update_cache=yes
- name: Install httpd
apt: pkg=httpd
- name: Start httpd
service: name=httpd state=running
还有我的inventory.yml:
[vagrant]
# Set at config.vm.network in the VagrantFile
10.0.0.111 ansible_connection=local ansible_ssh_port=2222 ansible_ssh_user=root ansible_ssh_pass=vagrant ansible_python_interpreter=/usr/bin/python2.6
我确实在虚拟机上安装了 python-apt 包,但仍然没有骰子。如果有人有任何提示,我很想听听。