diff --git a/app/models/embedded_ansible_worker/object_management.rb b/app/models/embedded_ansible_worker/object_management.rb index 82aecd770fe..6774ac6b425 100644 --- a/app/models/embedded_ansible_worker/object_management.rb +++ b/app/models/embedded_ansible_worker/object_management.rb @@ -6,6 +6,7 @@ def ensure_initial_objects(provider, connection) ensure_credential(provider, connection) ensure_inventory(provider, connection) ensure_host(provider, connection) + ensure_plugin_playbooks_project_seeded(connection) end def remove_demo_data(connection) @@ -54,24 +55,21 @@ def ensure_host(provider, connection) ).id end - #TODO: naming is hard - CONSOLIDATED_PLUGIN_PLAYBOOKS_TEMPDIR = Pathname.new("/var/lib/awx_consolidated_source/projects/blah").freeze + CONSOLIDATED_PLUGIN_PLAYBOOKS_TEMPDIR = Pathname.new("/var/lib/awx_consolidated_source/projects/gem_ansible_content").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 + if project = existing_plugin_playbook_project(connection) update_playbook_project(project) else - create_playbook_project + create_playbook_project(connection) 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 @@ -91,10 +89,19 @@ def copy_plugin_ansible_content 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"` + require 'rugged' + repo = Rugged::Repository.init_at(".") + index = repo.index + index.add_all("*") + index.write + + options = {} + options[:tree] = index.write_tree(repo) + options[:author] = options[:committer] = { :email => "user@example.com", :name => 'Author', :time => Time.now } + options[:message] = "YOLO Initial Commit" + options[:parents] = [] + options[:update_ref] = 'HEAD' + Rugged::Commit.create(repo, options) end end @@ -106,15 +113,15 @@ def commit_git_plugin_content :scm_update_on_launch => false }.freeze - def existing_plugin_playbook_project - @connection.api.projects.all(:name => PLUGIN_PLAYBOOK_PROJECT_NAME).first + def existing_plugin_playbook_project(connection) + 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) + def create_playbook_project(connection) + connection.api.projects.create!(PLAYBOOK_PROJECT_ATTRIBUTES.to_json) end end