Sha256: e9855d44543779d3b4f2f257122f10aed633f54e552832588a378a54cd30f70d

Contents?: true

Size: 1.51 KB

Versions: 53

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module ProxyAPI
  # ProxyAPI for Ansible
  class Ansible < ::ProxyAPI::Resource
    def initialize(args)
      @url = args[:url] + '/ansible/'
      super args
    end

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

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

    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

    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

    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

    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
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
foreman_ansible-12.0.5 app/lib/proxy_api/ansible.rb
foreman_ansible-10.4.3 app/lib/proxy_api/ansible.rb
foreman_ansible-12.0.4 app/lib/proxy_api/ansible.rb
foreman_ansible-10.4.2 app/lib/proxy_api/ansible.rb
foreman_ansible-12.0.3 app/lib/proxy_api/ansible.rb
foreman_ansible-12.0.2 app/lib/proxy_api/ansible.rb
foreman_ansible-12.0.1 app/lib/proxy_api/ansible.rb
foreman_ansible-12.0.0 app/lib/proxy_api/ansible.rb
foreman_ansible-11.2.1 app/lib/proxy_api/ansible.rb
foreman_ansible-7.1.7 app/lib/proxy_api/ansible.rb
foreman_ansible-11.2.0 app/lib/proxy_api/ansible.rb
foreman_ansible-11.1.2 app/lib/proxy_api/ansible.rb
foreman_ansible-7.1.6 app/lib/proxy_api/ansible.rb
foreman_ansible-11.1.1 app/lib/proxy_api/ansible.rb
foreman_ansible-10.4.1 app/lib/proxy_api/ansible.rb
foreman_ansible-7.1.5 app/lib/proxy_api/ansible.rb
foreman_ansible-11.1.0 app/lib/proxy_api/ansible.rb
foreman_ansible-10.4.0 app/lib/proxy_api/ansible.rb
foreman_ansible-10.3.0 app/lib/proxy_api/ansible.rb
foreman_ansible-11.0.0 app/lib/proxy_api/ansible.rb