Class: QB::Ansible::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/qb/ansible/env.rb

Direct Known Subclasses

Devel

Defined Under Namespace

Classes: Devel

Constant Summary collapse

VAR_NAME_PREFIX =

Constants

'ANSIBLE'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnv

Instantiate a new QB::Ansible::Env.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/qb/ansible/env.rb', line 70

def initialize
  # NOTE  this includes role paths pulled from a call-site local
  #       ansible.cfg
  @roles_path = QB::Role.search_path. # since QB::Role.search_path is an Array
    select(&:directory?).
    map(&:realpath). # so uniq works
    uniq # drop dups (seems to keep first instance so preserves priority)
  
  @library = [
    QB::ROOT.join('library'),
  ]
  
  @filter_plugins = [
    QB::ROOT.join('plugins', 'filter_plugins'),
  ]
  
  @lookup_plugins = [
    QB::ROOT.join('plugins', 'lookup_plugins'),
  ]
  
  @config = {}
end

Instance Attribute Details

#configHash<(String | Symbol), String] (readonly)

ANSIBLE_CONFIG_<name>=<value> ENV var values.

Returns:

  • (Hash<(String | Symbol), String])

    Hash<(String | Symbol), String]

See Also:



62
63
64
# File 'lib/qb/ansible/env.rb', line 62

def config
  @config
end

#filter_pluginsObject (readonly)

Returns the value of attribute filter_plugins.



48
49
50
# File 'lib/qb/ansible/env.rb', line 48

def filter_plugins
  @filter_plugins
end

#libraryObject (readonly)

Returns the value of attribute library.



43
44
45
# File 'lib/qb/ansible/env.rb', line 43

def library
  @library
end

#lookup_pluginsObject (readonly)

Returns the value of attribute lookup_plugins.



53
54
55
# File 'lib/qb/ansible/env.rb', line 53

def lookup_plugins
  @lookup_plugins
end

#roles_pathObject (readonly)

Returns the value of attribute roles_path.



38
39
40
# File 'lib/qb/ansible/env.rb', line 38

def roles_path
  @roles_path
end

Class Method Details

.to_var_name(name) ⇒ return_type

TODO:

Document to_var_name method.

Returns @todo Document return value.

Parameters:

  • name (type)

    @todo Add name param description.

Returns:

  • (return_type)

    @todo Document return value.



26
27
28
# File 'lib/qb/ansible/env.rb', line 26

def self.to_var_name name
  "#{ VAR_NAME_PREFIX }_#{ name.to_s.upcase }"
end

Instance Method Details

#to_hreturn_type

TODO:

Document to_h method.

Returns @todo Document return value.

Parameters:

  • arg_name (type)

    @todo Add name param description.

Returns:

  • (return_type)

    @todo Document return value.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/qb/ansible/env.rb', line 105

def to_h
  hash = [
    :roles_path,
    :library,
    :filter_plugins,
    :lookup_plugins
  ].map { |name|
    value = self.send name
    
    value = value.join(':') if value.is_a?(Array)
    
    [self.class.to_var_name(name), value]
  }.to_h
  
  config.each { |name, value|
    hash[ self.class.to_var_name( "CONFIG_#{ name }" ) ] = value.to_s
  }
  
  hash
end