-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use rugged to init the repo and do the initial commit
Seed plugin playbooks when populating initial objects
- Loading branch information
Showing
1 changed file
with
21 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 => "[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 | ||
|
||
|
@@ -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 |