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 awx as an embedded ansible plugin #16205

Merged
merged 12 commits into from
Dec 6, 2017

Conversation

carbonin
Copy link
Member

This fixes #15975

This PR builds on #16168 by adding a new EmbeddedAnsible plugin which handles running AWX.

AWX is the upstream of Ansible Tower and is distributed in a collection of containers rather than rpms.

The DockerEmbeddedAnsible class manages these containers using the docker-api gem.

When the role is enabled on an upstream appliance or on a development machine, we will pull the latest images, and run the containers using the same credential management system as we would in the appliance case.

The class also handles setting up the container environment required. This is mostly a ruby version of the playbook role that the AWX project uses to install the containers without all the image build and PG bits.

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

Very nice! 👍

require 'docker'
Docker.validate_version!
rescue RuntimeError
false
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should log something here in case the error is not what we are expecting?

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 wanted to avoid logging here because this could get called whenever we do EmbeddedAnsible.new which could be quite a lot in production.

I will look into if we can rescue a more specific error though.

@miq-bot
Copy link
Member

miq-bot commented Nov 6, 2017

This pull request is not mergeable. Please rebase and repush.

@carbonin carbonin force-pushed the add_awx_as_embedded_ansible_backend branch from e45b418 to 285ceda Compare November 7, 2017 14:52
end

def awx_task_image_name
"ansible/awx_task:latest"
Copy link
Member Author

Choose a reason for hiding this comment

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

Looking for suggestions around how to make this configurable.

Should I go for creating a new key in Settings?

Copy link
Member

Choose a reason for hiding this comment

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

👍 for Settings

@carbonin carbonin force-pushed the add_awx_as_embedded_ansible_backend branch from 285ceda to f04352a Compare November 17, 2017 21:41
@@ -43,9 +43,45 @@ def api_connection_raw(host, port)
)
end

def find_or_create_secret_key
miq_database.ansible_secret_key || miq_database.ansible_secret_key = SecureRandom.hex(16)
Copy link
Member

Choose a reason for hiding this comment

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

Will this be saved?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Can I persuade you to miq_database.ansible_secret_key ||= SecureRandom.hex(16)?

end

def database_configuration
@db_config ||= Rails.configuration.database_configuration[Rails.env]
Copy link
Member

Choose a reason for hiding this comment

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

Prefer ActiveRecord::Base.configurations. See #15269 for more info

def start
run_rabbitmq_container
run_memcached_container
sleep(15)
Copy link
Member

Choose a reason for hiding this comment

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

Is there something better that we could do? I assume we're waiting for rabbitmq and memcached to start, right?

Copy link
Member

Choose a reason for hiding this comment

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

Do the other containers have any of their own checks for these services?

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 actually yanked this directly from the playbook in ansible/awx

Because these are not "services" it seems harder to check their status.
Maybe we can pull the ncat checks into ManageIQ/manageiq in some way and reuse those here and in the pod in a follow up?

expect(connection).to receive(:select_value).with("CREATE DATABASE awx OWNER \"awx\" ENCODING 'utf8'")

auth = subject.send(:find_or_create_database_authentication)
expect(auth.userid).to eq("awx")
Copy link
Member

Choose a reason for hiding this comment

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

You can use have_attributes to reduce the number of expectations.

end

URI::HTTPS.build(:host => host, :path => path).to_s
Copy link
Member

Choose a reason for hiding this comment

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

Minor, but you can also code this up such that each path in the conditional creates a hash, with :scheme as one of the keys, then you can DRY up the URI, build, to_s bits down here into a single line.

auth
end

def generate_password
Copy link
Member

Choose a reason for hiding this comment

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

I can't tell if they aren't already, but these should probably be private methods from here down.

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, they're private starting at line 34

@Fryguy
Copy link
Member

Fryguy commented Nov 27, 2017

Looks good! Sorry about the delayed review.

@carbonin carbonin force-pushed the add_awx_as_embedded_ansible_backend branch 2 times, most recently from e42f543 to 13891f9 Compare November 28, 2017 21:35
@carbonin carbonin removed the wip label Nov 29, 2017
@carbonin carbonin changed the title [WIP] Add awx as an embedded ansible plugin Add awx as an embedded ansible plugin Nov 29, 2017
@carbonin carbonin changed the title Add awx as an embedded ansible plugin [WIP] Add awx as an embedded ansible plugin Nov 29, 2017
@carbonin
Copy link
Member Author

Leaving this as WIP until ManageIQ/manageiq-appliance-build#250 is merged which adds docker to the appliance.

@carbonin
Copy link
Member Author

carbonin commented Dec 4, 2017

Requires ManageIQ/manageiq-appliance#160

end

def find_or_create_admin_authentication
miq_database.ansible_admin_authentication || miq_database.set_ansible_admin_authentication(:password => generate_password)
Copy link
Member

Choose a reason for hiding this comment

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

Can these also be moved to miq_database.ansible_admin_authentication= then collapsed to ||= like 52bab34#r155362349 ?

@carbonin carbonin force-pushed the add_awx_as_embedded_ansible_backend branch from 74396f2 to 574a6c4 Compare December 6, 2017 22:28
This allows the "fetch from the database or generate and save"
behavior to be shared across different embedded ansible platforms
This will run the containers which make up AWX (https://github.com/ansible/awx)
and configure our app to use that for the embedded ansible feature.

This class uses the docker-api gem to communicate with the locally
running docker daemon to pull and launch the containers.

We use port 54321 as the host port so that this can be used
seamlessly in place of ApplianceEmbeddedAnsible when ansible tower
is not installed locally
When we have "localhost" in our database configuration, we have
to change that to the local machine's IP on the docker NIC
This also adds stubs for all of the subclass availability in each of
the specs to avoid sporadic test failures depending on the order
the subclasses are evaluated for availability.
This sorts the subclasses and instantiates the first available one
This error will be raised when the containers are just started.
Every API end point during the initial migration will return an
html page rather than a json payload.

This accounts for that specific situation by assuming if we don't
get a valid json response the service is not ready to serve requests
This really just assumes that a dev environment isn't multi-appliance
and isn't fronted by our httpd configuration.

This means that we always go to localhost, use http over https and
hardcode the port and path.
@carbonin carbonin force-pushed the add_awx_as_embedded_ansible_backend branch from 574a6c4 to b015723 Compare December 6, 2017 22:33
@miq-bot
Copy link
Member

miq-bot commented Dec 6, 2017

Checked commits carbonin/manageiq@a754fa8~...b015723 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
10 files checked, 1 offense detected

app/models/embedded_ansible_worker/runner.rb

end
end

private_constant :DockerDaemon
Copy link
Member

@bdunne bdunne Dec 6, 2017

Choose a reason for hiding this comment

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

:neckbeard: 💯


def docker_bridge_gateway
br = Docker::Network.get("bridge")
br.info["IPAM"]["Config"].first["Gateway"]
Copy link
Member

Choose a reason for hiding this comment

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

fetch_path FTW

@bdunne bdunne merged commit 5d27b97 into ManageIQ:master Dec 6, 2017
@bdunne bdunne added this to the Sprint 75 Ending Dec 11, 2017 milestone Dec 6, 2017
@bdunne bdunne assigned bdunne and unassigned gtanzillo Dec 6, 2017
@carbonin carbonin deleted the add_awx_as_embedded_ansible_backend branch December 6, 2017 23:26
simaishi pushed a commit that referenced this pull request Dec 11, 2017
…ackend

Add awx as an embedded ansible plugin
(cherry picked from commit 5d27b97)
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 1c5c1589982d848788a55aad0105dfd9b73fb5e3
Author: Brandon Dunne <[email protected]>
Date:   Wed Dec 6 17:52:22 2017 -0500

    Merge pull request #16205 from carbonin/add_awx_as_embedded_ansible_backend
    
    Add awx as an embedded ansible plugin
    (cherry picked from commit 5d27b9731bd9bb10bdf72a7058cd2d8ec128ce15)

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.

Bundle awx to ManageIQ appliance for simplify enabling Embeded Ansible.
6 participants