Class: Kitchen::Provisioner::SaltSolo

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/provisioner/salt_solo.rb

Overview

Basic Salt Masterless Provisioner, based on work by

Author:

Constant Summary collapse

RETCODE_VERSION =

salt-call version that supports the undocumented –retcode-passthrough command

'0.17.5'

Instance Method Summary collapse

Instance Method Details

#create_sandboxObject



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/kitchen/provisioner/salt_solo.rb', line 122

def create_sandbox
  super
  prepare_data
  prepare_minion
  prepare_state_top
  prepare_pillars
  if config[:state_collection]
    prepare_state_collection
  else
    prepare_formula
  end
end

#init_commandObject



135
136
137
138
139
# File 'lib/kitchen/provisioner/salt_solo.rb', line 135

def init_command
  debug("initialising Driver #{self.name}")
  data = File.join(config[:root_path], "data")
  "#{sudo('rm')} -rf #{data} ; mkdir -p #{config[:root_path]}"
end

#install_commandObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
# File 'lib/kitchen/provisioner/salt_solo.rb', line 57

def install_command
  debug(diagnose())
  salt_install = config[:salt_install]

  salt_url = config[:salt_bootstrap_url]
  chef_url = config[:chef_bootstrap_url]
  bootstrap_options = config[:salt_bootstrap_options]

  salt_version = config[:salt_version]
  salt_apt_repo = config[:salt_apt_repo]
  salt_apt_repo_key = config[:salt_apt_repo_key]

  <<-INSTALL
    sh -c '
    #{Util.shell_helpers}

    # what version of salt is installed?
    SALT_VERSION=`salt-call --version | cut -d " " -f 2`


    if [ -z "${SALT_VERSION}" -a "#{salt_install}" = "bootstrap" ]
    then
      do_download #{salt_url} /tmp/bootstrap-salt.sh
      #{sudo('sh')} /tmp/bootstrap-salt.sh #{bootstrap_options}
    elif [ -z "${SALT_VERSION}" -a "#{salt_install}" = "apt" ]
    then
      . /etc/lsb-release

      echo "deb #{salt_apt_repo}/salt-#{salt_version} ${DISTRIB_CODENAME} main" | #{sudo('tee')} /etc/apt/sources.list.d/salt-#{salt_version}.list

      do_download #{salt_apt_repo_key} /tmp/repo.key
      #{sudo('apt-key')} add /tmp/repo.key

      #{sudo('apt-get')} update
      #{sudo('apt-get')} install -y salt-minion
    elif [ -z "${SALT_VERSION}" ]
    then
      echo "No salt-minion installed and I do not know how to install one!"
      exit 2
    elif [ "${SALT_VERSION}" = "#{salt_version}" -o "#{salt_version}" = "latest" ]
    then
      echo "You asked for #{salt_version} and you have already got ${SALT_VERSION} installed, sweet!"
    elif [ ! -z "${SALT_VERSION}" -a "#{salt_install}" = "bootstrap" ]
    then
      echo "You asked for bootstrap install and you have got ${SALT_VERSION}, hope thats ok!"
    else
      echo "You asked for #{salt_version} and you have got ${SALT_VERSION} installed, dunno how to fix that, sorry!"
      exit 2
    fi

    # install chef omnibus so that busser works :(
    # TODO: work out how to install enough ruby
    # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
    # whole chef client
    if [ ! -d "/opt/chef" ]
    then
      echo "-----> Installing Chef Omnibus"
      do_download #{chef_url} /tmp/install.sh
      #{sudo('sh')} /tmp/install.sh
    fi

    '
  INSTALL
end

#run_commandObject



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/kitchen/provisioner/salt_solo.rb', line 141

def run_command
  debug("running driver #{self.name}")
  # sudo(File.join(config[:root_path], File.basename(config[:script])))
  debug(diagnose())
  if config[:salt_run_highstate]
    cmd = sudo("salt-call --config-dir=#{File.join(config[:root_path], config[:salt_config])} --local state.highstate")
  end

  cmd << " --log-level=#{config[:log_level]}"

  # config[:salt_version] can be 'latest' or 'x.y.z'
  if config[:salt_version] >= RETCODE_VERSION
    debug("Skipping the ropey --retcode-passthrough argument")
    # cmd = cmd + " --retcode-passthrough"
  else
    cmd << " 2>&1 | tee /tmp/salt-call-output ; grep -e ERROR -e CRITICAL /tmp/salt-call-output ; [ $? -eq 0 ] && exit 1 ; [ $? -eq 1 ] && exit 0 "
  end

  cmd
end