-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the Ansible service in containers rather than starting it locally #15423
Changes from all commits
36ea0ea
73992a4
0e9aed4
2115b1b
1ad05ba
dee942b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ class EmbeddedAnsible | |
WAIT_FOR_ANSIBLE_SLEEP = 1.second | ||
|
||
def self.available? | ||
return true if MiqEnvironment::Command.is_container? | ||
return false unless MiqEnvironment::Command.is_appliance? | ||
|
||
required_rpms = Set["ansible-tower-server", "ansible-tower-setup"] | ||
|
@@ -24,10 +25,12 @@ def self.enabled? | |
end | ||
|
||
def self.running? | ||
return true if MiqEnvironment::Command.is_container? | ||
services.all? { |service| LinuxAdmin::Service.new(service).running? } | ||
end | ||
|
||
def self.configured? | ||
return true if MiqEnvironment::Command.is_container? | ||
return false unless File.exist?(SECRET_KEY_FILE) | ||
key = miq_database.ansible_secret_key | ||
key.present? && key == File.read(SECRET_KEY_FILE) | ||
|
@@ -44,28 +47,20 @@ def self.alive? | |
end | ||
|
||
def self.start | ||
if configured? | ||
services.each { |service| LinuxAdmin::Service.new(service).start.enable } | ||
if MiqEnvironment::Command.is_container? | ||
container_start | ||
else | ||
configure_secret_key | ||
run_setup_script(EXCLUDE_TAGS) | ||
end | ||
|
||
5.times do | ||
return if alive? | ||
|
||
_log.info("Waiting for EmbeddedAnsible to respond") | ||
sleep WAIT_FOR_ANSIBLE_SLEEP | ||
appliance_start | ||
end | ||
|
||
raise "EmbeddedAnsible service is not responding after setup" | ||
end | ||
|
||
def self.stop | ||
return if MiqEnvironment::Command.is_container? | ||
services.each { |service| LinuxAdmin::Service.new(service).stop } | ||
end | ||
|
||
def self.disable | ||
return if MiqEnvironment::Command.is_container? | ||
services.each { |service| LinuxAdmin::Service.new(service).stop.disable } | ||
end | ||
|
||
|
@@ -74,14 +69,54 @@ def self.services | |
end | ||
|
||
def self.api_connection | ||
if MiqEnvironment::Command.is_container? | ||
host = ENV["ANSIBLE_SERVICE_NAME"] | ||
port = 80 | ||
else | ||
host = "localhost" | ||
port = HTTP_PORT | ||
end | ||
|
||
admin_auth = miq_database.ansible_admin_authentication | ||
AnsibleTowerClient::Connection.new( | ||
:base_url => URI::HTTP.build(:host => "localhost", :path => "/api/v1", :port => HTTP_PORT).to_s, | ||
:username => admin_auth.userid, | ||
:password => admin_auth.password | ||
:base_url => URI::HTTP.build(:host => host, :path => "/api/v1", :port => port).to_s, | ||
:username => admin_auth.userid, | ||
:password => admin_auth.password, | ||
:verify_ssl => 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙈 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's internal API that's not exposed externally, so not a problem |
||
) | ||
end | ||
|
||
def self.appliance_start | ||
if configured? | ||
services.each { |service| LinuxAdmin::Service.new(service).start.enable } | ||
else | ||
configure_secret_key | ||
run_setup_script(EXCLUDE_TAGS) | ||
end | ||
|
||
5.times do | ||
return if alive? | ||
|
||
_log.info("Waiting for EmbeddedAnsible to respond") | ||
sleep WAIT_FOR_ANSIBLE_SLEEP | ||
end | ||
|
||
raise "EmbeddedAnsible service is not responding after setup" | ||
end | ||
private_class_method :appliance_start | ||
|
||
def self.container_start | ||
miq_database.set_ansible_admin_authentication(:password => ENV["ANSIBLE_ADMIN_PASSWORD"]) | ||
|
||
loop do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooh, infinite loop? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason it's not 5.times... like the other places? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was treating this how we wait for other services in the container. |
||
break if alive? | ||
|
||
_log.info("Waiting for Ansible container to respond") | ||
sleep WAIT_FOR_ANSIBLE_SLEEP | ||
end | ||
end | ||
private_class_method :container_start | ||
|
||
def self.run_setup_script(exclude_tags) | ||
json_extra_vars = { | ||
:minimum_var_space => 0, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this isn't changed in this PR but here and the place we do the URI...build isn't checking if the
host
is nil. I'm not sure what we can do there but I believe this will blow up building the URI if it's nil.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better choice than blowing up?