Class: Vagrant::Provisioners::Ansible
- Inherits:
-
Base
- Object
- Base
- Vagrant::Provisioners::Ansible
- Includes:
- Util::SafeExec
- Defined in:
- lib/vagrant-ansible/provisioner.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- VERSION =
'0.0.5'
Class Method Summary collapse
Instance Method Summary collapse
- #provision! ⇒ Object
-
#with_inventory_file(ssh) ⇒ Object
This methods yield the path to a temporally created inventory file.
Class Method Details
.config_class ⇒ Object
44 45 46 |
# File 'lib/vagrant-ansible/provisioner.rb', line 44 def self.config_class Config end |
Instance Method Details
#provision! ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vagrant-ansible/provisioner.rb', line 76 def provision! ssh = env[:vm].config.ssh with_inventory_file(ssh) do |inventory_file| = %W[--user=#{ssh.username} --inventory-file=#{inventory_file} --private-key=#{env[:vm].env.default_private_key_path}] << "--ask-sudo-pass" if config.ask_sudo_pass << "--sudo" if config.sudo = + config. unless config..empty? cmd = (%w(ansible-playbook) << << config.playbook).flatten safe_exec *cmd end end |
#with_inventory_file(ssh) ⇒ Object
This methods yield the path to a temporally created inventory file.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vagrant-ansible/provisioner.rb', line 50 def with_inventory_file(ssh) if not config.inventory_file.nil? yield config.inventory_file else begin forward = env[:vm].config.vm.forwarded_ports.select do |x| x[:guestport] == ssh.guest_port end.first[:hostport] if not config.hosts.kind_of?(Array) config.hosts = [config.hosts] end file = Tempfile.new('inventory') config.hosts.each do |host| file.write("[#{host}]\n") file.write("#{ssh.host}:#{forward}\n") file.write("\n") end file.fsync file.close yield file.path ensure file.unlink end end end |