Skip to content

Instantly share code, notes, and snippets.

@robbmanes
Created September 19, 2018 14:55
Show Gist options
  • Save robbmanes/113fb8d8677b4874014a4f13b02a6a25 to your computer and use it in GitHub Desktop.
Save robbmanes/113fb8d8677b4874014a4f13b02a6a25 to your computer and use it in GitHub Desktop.
Add Ansible Tower Provider to ManageIQ or CloudForms
# This script adds an Ansible Tower Automation Manager to an existing CloudForms or ManageIQ instance.
# Fill in the required constansts for both Ansible Tower and CloudForms/ManageIQ
require 'rest-client'
require 'json'
CFME_URL = "https://my-manageiq.com"
CFME_USER = "admin"
CFME_PASSWORD = "smartvm"
TOWER_NAME = "my-ansible-tower-provider"
TOWER_URL = "my-ansible-tower.com"
TOWER_USER = "admin"
TOWER_PASSWORD = "tower"
payload = { "type": "ManageIQ::Providers::AnsibleTower::Provider",
"name": TOWER_NAME,
"url": TOWER_URL,
"credentials": {
"userid": TOWER_USER,
"password": TOWER_PASSWORD
}
}
payload = JSON.generate(payload)
begin
RestClient.log = 'stdout'
response = RestClient::Request.new(method: "post",
url: CFME_URL + "/api/providers?provider_class=provider",
payload: payload,
:headers => {:content_type=>"application/json"},
user: CFME_USER,
password: CFME_PASSWORD,
verify_ssl: false).execute
puts "Reply: #{response}"
rescue Exception => e
puts "Error: #{e.message}"
puts "Response: #{e.response}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment