Skip to content

Commit

Permalink
Use rugged to init the repo and do the initial commit
Browse files Browse the repository at this point in the history
Seed plugin playbooks when populating initial objects
  • Loading branch information
jrafanie committed Mar 22, 2018
1 parent bbec7c6 commit af75367
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions app/models/embedded_ansible_worker/object_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 => "[email protected]", :name => 'Author', :time => Time.now }
options[:message] = "YOLO Initial Commit"
options[:parents] = []
options[:update_ref] = 'HEAD'
Rugged::Commit.create(repo, options)
end
end

Expand All @@ -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

0 comments on commit af75367

Please sign in to comment.