Add ansible provisioner

This commit is contained in:
Collin Allen 2013-03-20 07:41:21 -07:00
parent 4ffc2c3b74
commit a1ad1207bd
4 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,46 @@
module VagrantPlugins
module Ansible
class Config < Vagrant.plugin("2", :config)
attr_accessor :playbook
attr_accessor :extra_vars
attr_accessor :inventory_file
attr_accessor :ask_sudo_pass
attr_accessor :limit
attr_accessor :sudo
attr_accessor :sudo_user
attr_accessor :verbose
def initialize
@playbook = UNSET_VALUE
@extra_vars = UNSET_VALUE
@inventory_file = UNSET_VALUE
@ask_sudo_pass = UNSET_VALUE
@limit = UNSET_VALUE
@sudo = UNSET_VALUE
@sudo_user = UNSET_VALUE
@verbose = UNSET_VALUE
end
def finalize!
@playbook = nil if @playbook == UNSET_VALUE
@extra_vars = nil if @extra_vars == UNSET_VALUE
@inventory_file = nil if @inventory_file == UNSET_VALUE
@ask_sudo_pass = nil if @ask_sudo_pass == UNSET_VALUE
@limit = nil if @limit == UNSET_VALUE
@sudo = nil if @sudo == UNSET_VALUE
@sudo_user = nil if @sudo_user == UNSET_VALUE
@verbose = nil if @verbose == UNSET_VALUE
end
def validate(machine)
errors = []
if !playbook
errors << I18n.t("vagrant.provisioners.ansible.no_playbook")
end
{ "ansible provisioner" => errors }
end
end
end
end

View File

@ -0,0 +1,23 @@
require "vagrant"
module VagrantPlugins
module Ansible
class Plugin < Vagrant.plugin("2")
name "ansible"
description <<-DESC
Provides support for provisioning your virtual machines with
Ansible playbooks.
DESC
config(:ansible, :provisioner) do
require_relative "config"
Config
end
provisioner(:ansible) do
require_relative "provisioner"
Provisioner
end
end
end
end

View File

@ -0,0 +1,28 @@
module VagrantPlugins
module Ansible
class Provisioner < Vagrant.plugin("2", :provisioner)
def provision
ssh = @machine.ssh_info
options = %W[--private-key=#{ssh[:private_key_path]} --user=#{ssh[:username]}]
options << "--extra-vars=\"#{config.extra_vars}\"" if config.extra_vars
options << "--inventory-file=#{config.inventory_file}" if config.inventory_file
options << "--ask-sudo-pass" if config.ask_sudo_pass
if config.limit
if not config.limit.kind_of?(Array)
config.limit = [config.limit]
end
config.limit = config.limit.join(",")
options << "--limit=#{config.limit}"
end
options << "--sudo" if config.sudo
options << "--sudo-user=#{config.sudo_user}" if config.sudo_user
options << "--verbose" if config.verbose
command = (%w(ansible-playbook) << options << config.playbook).flatten
Vagrant::Util::SafeExec.exec(*command)
end
end
end
end

View File

@ -1015,6 +1015,9 @@ en:
no_path_or_inline: "One of `path` or `inline` must be set." no_path_or_inline: "One of `path` or `inline` must be set."
path_invalid: "`path` for shell provisioner does not exist on the host system: %{path}" path_invalid: "`path` for shell provisioner does not exist on the host system: %{path}"
upload_path_not_set: "`upload_path` must be set for the shell provisioner." upload_path_not_set: "`upload_path` must be set for the shell provisioner."
ansible:
no_playbook: "`playbook` must be set for the ansible provisioner."
guest: guest:
base: base: