Skip to content

Instantly share code, notes, and snippets.

@bmbouter
Created February 3, 2020 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmbouter/8a0090b02e595349234a3c64fe563414 to your computer and use it in GitHub Desktop.
Save bmbouter/8a0090b02e595349234a3c64fe563414 to your computer and use it in GitHub Desktop.
import pdb
import subprocess
import tempfile
from pulpcore.client.pulp_ansible import (
DistributionsAnsibleApi,
RepositoriesAnsibleApi,
RepositorySyncURL,
RemotesAnsibleApi,
)
from pulp_smash.pulp3.utils import gen_distribution, gen_repo
from pulp_ansible.tests.functional.constants import (
ANSIBLE_ELASTIC_ROLE_NAMESPACE_NAME,
ANSIBLE_ELASTIC_ROLE_WHITELIST,
)
from pulp_ansible.tests.functional.utils import (
gen_ansible_client,
gen_ansible_remote,
monitor_task,
)
client = gen_ansible_client()
repo_api = RepositoriesAnsibleApi(client)
remote_role_api = RemotesAnsibleApi(client)
distributions_api = DistributionsAnsibleApi(client)
repo = repo_api.create(gen_repo())
pdb.set_trace()
# Create a Distribution.
body = {
"base_path": "production",
"name": "production",
"repository": repo.pulp_href
}
distribution_create = distributions_api.create(body)
distribution_url = monitor_task(distribution_create.task)
distribution = distributions_api.read(distribution_url[0])
pdb.set_trace()
# Create Remote
url = 'https://galaxy.ansible.com/api/v1/roles/?namespace__name=elastic'
body = gen_ansible_remote(url=url)
remote = remote_role_api.create(body)
pdb.set_trace()
# Sync the repository.
repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
monitor_task(sync_response.task)
repo = repo_api.read(repo.pulp_href)
with tempfile.TemporaryDirectory() as temp_dir:
cmd = "ansible-galaxy role install {} -c -s {} -p {}".format(
ANSIBLE_ELASTIC_ROLE_WHITELIST, distribution.client_url, temp_dir
)
print(cmd)
pdb.set_trace()
directory = "{}/{}".format(temp_dir, ANSIBLE_ELASTIC_ROLE_NAMESPACE_NAME)
subprocess.run(cmd.split())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment