Class: VagrantPlugins::GuestAnsible::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-guest_ansible/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vagrant-guest_ansible/config.rb', line 23

def initialize
  @playbook = UNSET_VALUE
  @extra_vars = UNSET_VALUE
  @inventory_path = UNSET_VALUE
  @ask_sudo_pass = UNSET_VALUE
  @limit = UNSET_VALUE
  @sudo = UNSET_VALUE
  @sudo_user = UNSET_VALUE
  @verbose = UNSET_VALUE
  @tags = UNSET_VALUE
  @skip_tags = UNSET_VALUE
  @start_at_task = UNSET_VALUE
  @raw_arguments = UNSET_VALUE
  @groups = UNSET_VALUE
  @host_key_checking = "true"
end

Instance Attribute Details

#ask_sudo_passObject

Returns the value of attribute ask_sudo_pass.



9
10
11
# File 'lib/vagrant-guest_ansible/config.rb', line 9

def ask_sudo_pass
  @ask_sudo_pass
end

#extra_varsObject

Returns the value of attribute extra_vars.



7
8
9
# File 'lib/vagrant-guest_ansible/config.rb', line 7

def extra_vars
  @extra_vars
end

#groupsObject

Returns the value of attribute groups.



17
18
19
# File 'lib/vagrant-guest_ansible/config.rb', line 17

def groups
  @groups
end

#host_key_checkingObject

Returns the value of attribute host_key_checking.



18
19
20
# File 'lib/vagrant-guest_ansible/config.rb', line 18

def host_key_checking
  @host_key_checking
end

#inventory_pathObject

Returns the value of attribute inventory_path.



8
9
10
# File 'lib/vagrant-guest_ansible/config.rb', line 8

def inventory_path
  @inventory_path
end

#limitObject

Returns the value of attribute limit.



10
11
12
# File 'lib/vagrant-guest_ansible/config.rb', line 10

def limit
  @limit
end

#playbookObject

Returns the value of attribute playbook.



6
7
8
# File 'lib/vagrant-guest_ansible/config.rb', line 6

def playbook
  @playbook
end

#raw_argumentsObject

Joker attribute, used to pass unsupported arguments to ansible anyway



21
22
23
# File 'lib/vagrant-guest_ansible/config.rb', line 21

def raw_arguments
  @raw_arguments
end

#skip_tagsObject

Returns the value of attribute skip_tags.



15
16
17
# File 'lib/vagrant-guest_ansible/config.rb', line 15

def skip_tags
  @skip_tags
end

#start_at_taskObject

Returns the value of attribute start_at_task.



16
17
18
# File 'lib/vagrant-guest_ansible/config.rb', line 16

def start_at_task
  @start_at_task
end

#sudoObject

Returns the value of attribute sudo.



11
12
13
# File 'lib/vagrant-guest_ansible/config.rb', line 11

def sudo
  @sudo
end

#sudo_userObject

Returns the value of attribute sudo_user.



12
13
14
# File 'lib/vagrant-guest_ansible/config.rb', line 12

def sudo_user
  @sudo_user
end

#tagsObject

Returns the value of attribute tags.



14
15
16
# File 'lib/vagrant-guest_ansible/config.rb', line 14

def tags
  @tags
end

#verboseObject

Returns the value of attribute verbose.



13
14
15
# File 'lib/vagrant-guest_ansible/config.rb', line 13

def verbose
  @verbose
end

Instance Method Details

#binaryObject



52
53
54
# File 'lib/vagrant-guest_ansible/config.rb', line 52

def binary
  false
end

#finalize!Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/vagrant-guest_ansible/config.rb', line 56

def finalize!
  @playbook = nil if @playbook == UNSET_VALUE
  @extra_vars = nil if @extra_vars == UNSET_VALUE
  @inventory_path = nil if @inventory_path == 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
  @tags = nil if @tags == UNSET_VALUE
  @skip_tags = nil if @skip_tags == UNSET_VALUE
  @start_at_task = nil if @start_at_task == UNSET_VALUE
  @raw_arguments = nil if @raw_arguments == UNSET_VALUE
  @groups = {} if @groups == UNSET_VALUE
  @host_key_checking = nil if @host_key_checking == UNSET_VALUE
end

#pathObject



40
41
42
# File 'lib/vagrant-guest_ansible/config.rb', line 40

def path
  @path ||= File.expand_path("../guest_script.sh", __FILE__)
end

#remote?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/vagrant-guest_ansible/config.rb', line 48

def remote?
  path =~ URI.regexp(["ftp", "http", "https"])
end

#upload_pathObject



44
45
46
# File 'lib/vagrant-guest_ansible/config.rb', line 44

def upload_path
  "/tmp/vagrant-shell"
end

#validate(machine) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/vagrant-guest_ansible/config.rb', line 73

def validate(machine)
  errors = _detected_errors

  # Validate that a playbook path was provided
  if !playbook
    errors << I18n.t("vagrant.provisioners.ansible.no_playbook")
  end

  # Validate the existence of said playbook on the host
  if playbook
    expanded_path = Pathname.new(playbook).expand_path(machine.env.root_path)
    if !expanded_path.file?
      errors << I18n.t("vagrant.provisioners.ansible.playbook_path_invalid",
                        :path => expanded_path)
    end
  end

  # Validate that extra_vars is either a hash, or a path to an
  # existing file
  if extra_vars
    extra_vars_is_valid = extra_vars.kind_of?(Hash) || extra_vars.kind_of?(String)
    if extra_vars.kind_of?(String)
      # Accept the usage of '@' prefix in Vagrantfile (e.g. '@vars.yml'
      # and 'vars.yml' are both supported)
      match_data = /^@?(.+)$/.match(extra_vars)
      extra_vars_path = match_data[1].to_s
      expanded_path = Pathname.new(extra_vars_path).expand_path(machine.env.root_path)
      extra_vars_is_valid = expanded_path.exist?
      if extra_vars_is_valid
        @extra_vars = '@' + extra_vars_path
      end
    end

    if !extra_vars_is_valid
      errors << I18n.t("vagrant.provisioners.ansible.extra_vars_invalid",
                        :type => extra_vars.class.to_s,
                        :value => extra_vars.to_s
                      )
    end
  end

  # Validate the existence of the inventory_path, if specified
  if inventory_path
    expanded_path = Pathname.new(inventory_path).expand_path(machine.env.root_path)
    if !expanded_path.exist?
      errors << I18n.t("vagrant.provisioners.ansible.inventory_path_invalid",
                        :path => expanded_path)
    end
  end

  { "ansible provisioner" => errors }
end