1
我寫了一本安裝Docker的劇本。如何強制在Vagrant機器上運行劇本?
---
- name: Install dependencies
apt: name={{ item }} state=present update_cache=yes
with_items:
- linux-image-generic-lts-{{ ansible_distribution_release }}
- linux-headers-generic-lts-{{ ansible_distribution_release }}
become: true
- name: Add Docker repository key
apt_key:
id: 58118E89F3A912897C070ADBF76221572C52609D
keyserver: hkp://p80.pool.sks-keyservers.net:80
state: present
register: add_repository_key
become: true
- name: Add Docker repository
apt_repository:
repo: 'deb https://apt.dockerproject.org/repo {{ ansible_distribution_release }} main'
state: present
become: true
- name: Install Docker
apt:
name: docker
state: latest
update_cache: yes
become: true
- name: Verify the service is running
service:
name: docker
enabled: yes
state: started
become: true
我在配置使用該劇本的流浪者機器。
Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.ssh.insert_key = false
config.vm.synced_folder "./", "/tmp/project",create: true
config.vm.network :forwarded_port, guest: 80, host: 80 , auto_correct: true
config.vm.provider :virtualbox do |v|
# Name of machine
v.name = "default"
# Machine memory
v.memory = 1024
# Number of cpu's
v.cpus = 2
# This option makes the NAT engine use the host's resolver mechanisms to handle DNS requests
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
# Enabling the I/O APIC is required for 64-bit guest operating systems; it is also required if you want to use more than one virtual CPU in a virtual machine.
v.customize ["modifyvm", :id, "--ioapic", "on"]
end
config.vm.provision "ansible" do |ansible|
# Sets the playbook to use when machine is up'ed
ansible.playbook = "deploy/main.yml"
end
end
但由於某些原因,這就是輸出I get和碼頭工人沒有流浪機器上安裝:
$ vagrant up --provision
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Running provisioner: ansible...
default: Running ansible-playbook...
PLAY RECAP *********************************************************************
這是做到這一點的正確方法?
是否有一個命令可以讓我在正在運行的Vagrant機器上播放劇本?