Sha256: 7dee0a2aeb3a898af9976b601bc7200832d7345c474cc0c72526f99c22343e6a

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

# Requirements
# =====================================================================

# package
require 'qb/ansible/cmds/playbook'


module QB; end

# @todo document QB::CLI module.
module QB::CLI 
  
  # Play an Ansible playbook (like `state.yml`) in the QB environment 
  # (sets up path env vars, IO streams, etc.).
  # 
  # @param [type] arg_name
  #   @todo Add name param description.
  # 
  # @return [return_type]
  #   @todo Document return value.
  # 
  def self.play args
    if args.empty?
      raise "Need path to playbook in first arg."
    end
    
    playbook_path = QB::Util.resolve args[0]
    
    unless playbook_path.file?
      raise "Can't find Ansible playbook at #{ path.to_s }"
    end
    
    # By default, we won't change directories to run the command.
    chdir = nil
    
    # See if there is an Ansible config in the parent directories
    ansible_cfg_path = QB::Util.find_up \
      QB::Ansible::ConfigFile::FILE_NAME,
      playbook_path.dirname,
      raise_on_not_found: false
    
    # If we did find an Ansible config, we're going to want to run in that
    # directory and add it to the role search path so that we merge it's 
    # values into our env vars (otherwise they would override the config
    # values).
    unless ansible_cfg_path.nil?
      QB::Role::PATH.unshift ansible_cfg_path.dirname
      chdir = ansible_cfg_path.dirname
    end
    
    cmd = QB::Ansible::Cmds::Playbook.new \
      playbook_path: playbook_path,
      chdir: chdir
    
  end # .play
  
end # module QB::CLI


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qb-0.3.4 lib/qb/cli/play.rb