Class: ProxyAPI::Ansible

Inherits:
Resource
  • Object
show all
Defined in:
app/lib/proxy_api/ansible.rb

Overview

ProxyAPI for Ansible

Constant Summary collapse

PROXY_ERRORS =
[
  Errno::ECONNREFUSED,
  SocketError,
  Timeout::Error,
  Errno::EINVAL,
  Errno::ECONNRESET,
  EOFError,
  Net::HTTPBadResponse,
  Net::HTTPHeaderSyntaxError,
  Net::ProtocolError,
  RestClient::ResourceNotFound
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Ansible

Returns a new instance of Ansible.



6
7
8
9
# File 'app/lib/proxy_api/ansible.rb', line 6

def initialize(args)
  @url = args[:url] + '/ansible/'
  super args
end

Instance Method Details

#all_variablesObject



30
31
32
33
34
35
# File 'app/lib/proxy_api/ansible.rb', line 30

def all_variables
  parse(get('roles/variables'))
rescue *PROXY_ERRORS => e
  raise ProxyException.new(url, e,
                           N_('Unable to get roles/variables from Ansible'))
end

#playbooks(playbooks_names = []) ⇒ Object



50
51
52
53
54
55
# File 'app/lib/proxy_api/ansible.rb', line 50

def playbooks(playbooks_names = [])
  playbooks_names = playbooks_names.join(',')
  parse(get("playbooks/#{playbooks_names}"))
rescue *PROXY_ERRORS => e
  raise ProxyException.new(url, e, N_('Unable to get playbooks from Ansible'))
end

#playbooks_namesObject



44
45
46
47
48
# File 'app/lib/proxy_api/ansible.rb', line 44

def playbooks_names
  parse(get('playbooks_names'))
rescue *PROXY_ERRORS => e
  raise ProxyException.new(url, e, N_('Unable to get playbook\'s names from Ansible'))
end

#rolesObject



24
25
26
27
28
# File 'app/lib/proxy_api/ansible.rb', line 24

def roles
  parse(get('roles'))
rescue *PROXY_ERRORS => e
  raise ProxyException.new(url, e, N_('Unable to get roles from Ansible'))
end

#variables(role) ⇒ Object



37
38
39
40
41
42
# File 'app/lib/proxy_api/ansible.rb', line 37

def variables(role)
  parse(get("roles/#{role}/variables"))
rescue *PROXY_ERRORS => e
  raise ProxyException.new(url, e,
                           N_('Unable to get roles/variables from Ansible'))
end