Skip to content

Commit

Permalink
Initial add
Browse files Browse the repository at this point in the history
TODO: Write tests, ruggedize this, make sure role activation run this
and make sure it works 😅

All of this depends on:
https://github.com/ManageIQ/ManageIQ/manageiq/pull/17096
ManageIQ/manageiq-content#254
  • Loading branch information
jrafanie committed Mar 22, 2018
1 parent 388f266 commit bbec7c6
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions app/models/embedded_ansible_worker/object_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,68 @@ def ensure_host(provider, connection)
:variables => {'ansible_connection' => "local"}.to_yaml
).id
end

#TODO: naming is hard
CONSOLIDATED_PLUGIN_PLAYBOOKS_TEMPDIR = Pathname.new("/var/lib/awx_consolidated_source/projects/blah").freeze
def ensure_plugin_playbooks_project_seeded(connection)
@connection = connection
clean_consolidated_plugin_directory
copy_plugin_ansible_content

commit_git_plugin_content

if project = existing_plugin_playbook_project
update_playbook_project(project)
else
create_playbook_project
end
ensure
# we already have 2 copies: one in the gem and one imported into ansible in the project, delete the temporary one
clean_consolidated_plugin_directory
@connection = nil
end

private

def clean_consolidated_plugin_directory
FileUtils.rm_rf(CONSOLIDATED_PLUGIN_PLAYBOOKS_TEMPDIR)
end

def copy_plugin_ansible_content
FileUtils.mkdir_p(CONSOLIDATED_PLUGIN_PLAYBOOKS_TEMPDIR)

#TODO: make this a public api via an attr_reader
Vmdb::Plugins.instance.instance_variable_get(:@registered_ansible_content).each do |content|
FileUtils.cp_r(Dir.glob("#{content.path}/*"), CONSOLIDATED_PLUGIN_PLAYBOOKS_TEMPDIR)
end
end

def commit_git_plugin_content
Dir.chdir(CONSOLIDATED_PLUGIN_PLAYBOOKS_TEMPDIR) do
# ruggedize this
`git init`
`git add -A`
`git commit -m "YOLO Initial Commit"`
end
end

PLUGIN_PLAYBOOK_PROJECT_NAME = "Default ManageIQ Playbook Project".freeze
PLAYBOOK_PROJECT_ATTRIBUTES = {
:name => PLUGIN_PLAYBOOK_PROJECT_NAME,
:scm_type => "git",
:scm_url => "file:://#{CONSOLIDATED_PLUGIN_PLAYBOOKS_TEMPDIR}",
:scm_update_on_launch => false
}.freeze

def existing_plugin_playbook_project
@connection.api.projects.all(:name => PLUGIN_PLAYBOOK_PROJECT_NAME).first
end

def update_playbook_project(project)
project.update_attributes!(PLAYBOOK_PROJECT_ATTRIBUTES)
end

def create_playbook_project
@connection.api.projects.create!(PLAYBOOK_PROJECT_ATTRIBUTES.to_json)
end
end

0 comments on commit bbec7c6

Please sign in to comment.