Skip to content
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

Add methods for configuring and starting ansible inside #13584

Merged
merged 14 commits into from
Jan 26, 2017

Conversation

carbonin
Copy link
Member

This PR mainly fleshes out the EmbeddedAnsible class created in #13435

This adds things like configuring the appliance to run the ansible service and methods for managing that service.

Also added here is a way to share the keys and passwords needed by the embedded ansible service across servers in case of role failover.

This is the general shape of the API that will be used by the worker being created in #13551

https://www.pivotaltracker.com/story/show/137048481

@@ -11,13 +17,114 @@ def self.enabled?
end

def self.running?
# TODO
false
services.map { |service| LinuxAdmin::Service.new(service).running? }.inject(:&)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not sure why I did it that way ... all? is probably the better way to go ...


auth.password = password
auth.save!
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not for this PR, but the repetition of the ansible_ prefix for the methods and the hardcoded authtypes make me think we should have a ansible thing mixed in here or a separate class so we can have constants and less code here. Maybe we can start with making constants out of the hardcoded values?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, seems weird to have so many "ansible" specific references in MiqDatabase. It may seem like overkill for now, but maybe a new model for "appliance services" or something like that where ansible could be on of them. Just spitballing here...

rabbitmq_vhost=tower
rabbitmq_username=tower
rabbitmq_password='#{rabbitmq_password}'
rabbitmq_cookie=cookiemonster
Copy link
Member

@jrafanie jrafanie Jan 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, that's their default, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, pulled this all from the default file 😄

with_inventory_file do |inventory_file_path|
setup_params = {
:e => "minimum_var_space=0",
:k => "packages,migrations,supervisor",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to put this list into a explaining constant/variable/method so it's obvious why one has supervisor in the list and the one below doesn't?

end
end

def self.stop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to name this method "disable"? I think we can assume disabling a service should stop it but I don't think you can assume stopping a service should disable it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Do you think we should also have a .stop?

file.close
yield(file.path)
ensure
file.unlink
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the file.close is done automatically if you use Tempfile.new with a block. Are you trying to avoid having the GC do the unlink through a finalizer?

In other words, why not:

Tempfile.open("miq_inventory") do |file|
  file.write(inventory_file_contents)
  yield(file.path)
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I ran into an issue where the contents of the tempfile were not synced to the filesystem unless I did the #close. So when we then do a File.read("temp/file/path") we didn't get the proper contents.

May have made that up though.

Copy link
Member Author

@carbonin carbonin Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do this extra #close to get the .configured? specs to pass, for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, the link is now dead. I'm ok with doing this if we really need make sure the file is gone. I think the difference is the unlink could be delayed until the Tempfile object is GC'd so the file could stay around longer than expected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would want this file gone ASAP as it will contain passwords.

These methods run the setup playbook with particular arguments
to accomplish configuration and startup at different times.

Also added stop and running? methods to control and monitor the
services running on the server
These methods will be used to store authentication information
and shared keys that will be used whenever we start the ansible
role on a server.
This determines if the service is configured based on the status
of the secret key.
This allows us to run nginx alongside apache withou hacking an
edit on the configuration file at install time.
The firewall task opens the ports we specify to use for nginx.
We want to control the appliance's firewall and we don't want nginx
to be able to get through.
This avoids unpleasant quoting and escaping issues within the
inventory file.
There's no reason for this to be in the console or elsewhere.
We can manage the creation of the database the same way we manage
the secret key. Create it if we think we need to.

We are using the presence of the database password to determine
if the database needs to be created.
The `.stop` method now just stops the services and the `.disable`
method will stop then disable each service.
Also fix a brakeman falure by quoting the password for SQL when
creating the awx role.
@miq-bot
Copy link
Member

miq-bot commented Jan 25, 2017

Checked commits carbonin/manageiq@d0873c5~...d277d40 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks good. 🏆

@carbonin carbonin changed the title [WIP] Add methods for configuring and starting ansible inside Add methods for configuring and starting ansible inside Jan 26, 2017
private_class_method :playbook_extra_variables

def self.run_setup_script(params)
with_inventory_file do |inventory_file_path|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wrap this with a flock or something to avoid the possibility of the worker running more than one of these at once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this in a followup PR.

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pounded this PR through some manual test runs and found some minor things for follow up PRs but it's all good.

👍

@jrafanie jrafanie merged commit b3ade89 into ManageIQ:master Jan 26, 2017
@jrafanie jrafanie added this to the Sprint 53 Ending Jan 30, 2017 milestone Jan 26, 2017
@carbonin carbonin deleted the ansible_inside branch March 7, 2017 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants