module Shelter::CLI::Helpers::Ansible
Mixin module for Ansible
Public Instance Methods
ansible_execute(playbook, options = {})
click to toggle source
server_user: nil, inventory: nil, tags: [], skip: [], limit: nil
# File lib/cli/helpers/ansible_helper.rb 42 def ansible_execute(playbook, options = {}) 43 params = { 44 inventory: nil, server_user: nil, tags: [], skip: [], limit: nil 45 }.merge(options) 46 command = [command_bin, inventory_file(params[:inventory]), 47 vault_password_file] 48 command += new_server_params(params[:server_user]) 49 command += optional_params(params) 50 command << "#{App.config.ansible_directory}/#{playbook}.yaml" 51 52 full_command = command.join(' ') 53 system full_command 54 end
command_bin()
click to toggle source
# File lib/cli/helpers/ansible_helper.rb 20 def command_bin 21 'ansible-playbook' 22 end
inventory_file(inventory)
click to toggle source
# File lib/cli/helpers/ansible_helper.rb 15 def inventory_file(inventory) 16 inventory ||= App.config.inventory_script 17 "--inventory #{inventory}" 18 end
new_server_params(server_user)
click to toggle source
# File lib/cli/helpers/ansible_helper.rb 24 def new_server_params(server_user) 25 command = [] 26 command << "--user #{server_user} --ask-pass" unless server_user.nil? 27 command 28 end
optional_params(opts)
click to toggle source
# File lib/cli/helpers/ansible_helper.rb 30 def optional_params(opts) 31 command = [] 32 command << "--tags '#{opts[:tags].join(',')}'" unless 33 opts[:tags].empty? 34 command << "--skip-tags '#{opts[:skip].join(',')}'" unless 35 opts[:skip].empty? 36 command << "--limit '#{opts[:limit]}'" unless opts[:limit].nil? 37 command 38 end
vault_execute(command, file)
click to toggle source
# File lib/cli/helpers/ansible_helper.rb 56 def vault_execute(command, file) 57 file = "/#{file}" unless file.start_with?('/') 58 file = "#{App.config.secure_root}#{file}_secret.yaml" 59 system "ansible-vault #{command} #{vault_password_file} #{file}" 60 end
vault_password_file()
click to toggle source
# File lib/cli/helpers/ansible_helper.rb 8 def vault_password_file 9 [ 10 '--vault-password-file', 11 "#{App.config.secure_root}/ansible_vault_password" 12 ].join(' ') 13 end