module Taperole::AnsibleRunner
Protected Instance Methods
ansible(args: '', options: {})
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 30 def ansible(args: '', options: {}) exec_ansible("#{tapefiles_dir}/provision.yml", args, options) end
ansible_custom_playbook(args: '', options: {})
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 38 def ansible_custom_playbook(args: '', options: {}) exec_ansible("#{tapefiles_dir}/#{options[:book]}", args, options) end
ansible_deploy(args: '', options: {})
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 34 def ansible_deploy(args: '', options: {}) exec_ansible("#{tapefiles_dir}/deploy.yml", args, options) end
ansible_rake_task(options: {})
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 42 def ansible_rake_task(options: {}) exec_ansible("#{tapefiles_dir}/rake.yml", "--extra-vars \"task=#{options[:task]}\"", options) end
enforce_roles_path!()
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 63 def enforce_roles_path! Dir.mkdir('.tape') unless Dir.exist?('.tape') config_file = "#{local_dir}/.tape/ansible.cfg" return if File.exist?(config_file) File.open(config_file, 'w') do |f| f.puts '[defaults]' f.puts "roles_path=.tape/roles:#{tape_dir}/roles:#{tape_dir}/vendor" f.puts "inventory=#{tapefiles_dir}/hosts" f.puts "retries-dir=/dev/null" f.puts "retry_files_enabled = False" f.puts '[ssh_connection]' f.puts 'ssh_args=-o ForwardAgent=yes' end end
exec_ansible(playbook, args, options)
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 46 def exec_ansible(playbook, args, options) enforce_roles_path! cmd = "ANSIBLE_CONFIG=#{local_dir}/.tape/ansible.cfg ansible-playbook -i" cmd += " #{inventory_file(options)} #{playbook} #{args} #{hosts_flag(options)}" cmd += " -e \"#{extra_vars(options)}\"" cmd += ' --ask-vault-pass' if options['ask-vault-pass'] cmd += ' -vvvv' if options[:verbose] cmd += " -t #{options[:tags]}" if options[:tags] logger.info "Executing: #{cmd}" if options[:verbose] Taperole::Notifier.notify_observers(:start) if Kernel.system(cmd) Taperole::Notifier.notify_observers(:success) else Taperole::Notifier.notify_observers(:fail) end end
extra_vars(options)
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 80 def extra_vars(options) base_vars = "tape_dir=#{tape_dir}" extra_vars = options[:extras] if extra_vars base_vars + " " + extra_vars else base_vars end end
has_gem_in_gemfile?(name)
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 21 def has_gem_in_gemfile?(name) if open('Gemfile').grep(/#{name}/).empty? logger.error "💥 ERROR: Add #{name} to your Gemfile!💥 ".red false else true end end
hosts_flag(options)
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 91 def hosts_flag(options) limit = options[:limit] "-l #{limit}" if limit end
inventory_file(options)
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 96 def inventory_file(options) options[:inventory_file] || "#{tapefiles_dir}/hosts" end
valid_gems()
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 17 def valid_gems has_gem_in_gemfile?('puma') end
valid_preconfigs()
click to toggle source
# File lib/taperole/core/ansible_runner.rb, line 7 def valid_preconfigs if rails_app? valid_gems elsif fe_app? true else false end end