diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index a31a203257..cd9b6923ab 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -81,8 +81,8 @@ class GalaxyCLI(CLI): self.parser.set_usage("usage: %prog init [options] role_name") self.parser.add_option('--init-path', dest='init_path', default="./", help='The path in which the skeleton role will be created. The default is the current working directory.') - self.parser.add_option('--container-enabled', dest='container_enabled', action='store_true', default=False, - help='Initialize the skeleton role with default contents for a Container Enabled role.') + self.parser.add_option('--type', dest='role_type', action='store', default='default', + help="Initialize using an alternate role type. Valid types include: 'container', and 'apb'.") self.parser.add_option('--role-skeleton', dest='role_skeleton', default=C.GALAXY_ROLE_SKELETON, help='The path to a role skeleton that the new role should be based upon.') elif self.action == "install": @@ -214,7 +214,7 @@ class GalaxyCLI(CLI): license='license (GPLv2, CC-BY, etc)', issue_tracker_url='http://example.com/issue/tracker', min_ansible_version='1.2', - container_enabled=self.options.container_enabled + role_type=self.options.role_type ) # create role directory diff --git a/lib/ansible/galaxy/__init__.py b/lib/ansible/galaxy/__init__.py index fb18f75619..b9048d3db5 100644 --- a/lib/ansible/galaxy/__init__.py +++ b/lib/ansible/galaxy/__init__.py @@ -47,7 +47,7 @@ class Galaxy(object): # load data path for resource usage this_dir, this_filename = os.path.split(__file__) - type_path = 'container_enabled' if getattr(self.options, 'container_enabled', False) else 'default' + type_path = getattr(self.options, 'role_type', "default") self.DATA_PATH = os.path.join(this_dir, 'data', type_path) @property diff --git a/lib/ansible/galaxy/data/apb/.travis.yml b/lib/ansible/galaxy/data/apb/.travis.yml new file mode 100644 index 0000000000..93b5be42a2 --- /dev/null +++ b/lib/ansible/galaxy/data/apb/.travis.yml @@ -0,0 +1,26 @@ +--- +services: docker +sudo: required +language: python +python: + - '2.7' + +env: + - OPENSHIFT_VERSION=latest + - OPENSHIFT_VERSION=v3.9 + - KUBERNETES_VERSION=latest + - KUBERNETES_VERSION=v1.9.0 + +script: + # Configure test values + - export apb_name=APB_NAME + + # Download test shim. + - wget -O ${PWD}/apb-test.sh https://raw.githubusercontent.com/djzager/apb-test-shim/ansible-galaxy/apb-test.sh + - chmod +x ${PWD}/apb-test.sh + + # Run tests. + - ${PWD}/apb-test.sh + +# notifications: +# webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/lib/ansible/galaxy/data/apb/Dockerfile.j2 b/lib/ansible/galaxy/data/apb/Dockerfile.j2 new file mode 100644 index 0000000000..645bb4b750 --- /dev/null +++ b/lib/ansible/galaxy/data/apb/Dockerfile.j2 @@ -0,0 +1,8 @@ +FROM ansibleplaybookbundle/apb-base + +LABEL "com.redhat.apb.spec"=\ + +COPY playbooks /opt/apb/actions +COPY . /opt/ansible/roles/{{ role_name }} +RUN chmod -R g=u /opt/{ansible,apb} +USER apb diff --git a/lib/ansible/galaxy/data/apb/Makefile.j2 b/lib/ansible/galaxy/data/apb/Makefile.j2 new file mode 100644 index 0000000000..ebeaa61f16 --- /dev/null +++ b/lib/ansible/galaxy/data/apb/Makefile.j2 @@ -0,0 +1,21 @@ +DOCKERHOST = DOCKERHOST +DOCKERORG = DOCKERORG +IMAGENAME = {{ role_name }} +TAG = latest +USER=$(shell id -u) +PWD=$(shell pwd) +build_and_push: apb_build docker_push apb_push + +.PHONY: apb_build +apb_build: + docker run --rm --privileged -v $(PWD):/mnt:z -v $(HOME)/.kube:/.kube -v /var/run/docker.sock:/var/run/docker.sock -u $(USER) docker.io/ansibleplaybookbundle/apb-tools:latest prepare + docker build -t $(DOCKERHOST)/$(DOCKERORG)/$(IMAGENAME):$(TAG) . + +.PHONY: docker_push +docker_push: + docker push $(DOCKERHOST)/$(DOCKERORG)/$(IMAGENAME):$(TAG) + +.PHONY: apb_push +apb_push: + docker run --rm --privileged -v $(PWD):/mnt:z -v $(HOME)/.kube:/.kube -v /var/run/docker.sock:/var/run/docker.sock -u $(USER) docker.io/ansibleplaybookbundle/apb-tools:latest push + diff --git a/lib/ansible/galaxy/data/apb/README.md b/lib/ansible/galaxy/data/apb/README.md new file mode 100644 index 0000000000..2e350a03fd --- /dev/null +++ b/lib/ansible/galaxy/data/apb/README.md @@ -0,0 +1,38 @@ +APB Name +========= + +A brief description of the APB goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +APB Variables +-------------- + +A description of the settable variables for this APB should go here, including any variables that are in defaults/main.yml, vars/main.yml, apb.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (i.e. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other APBs/roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your APB (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/lib/ansible/galaxy/data/apb/apb.yml.j2 b/lib/ansible/galaxy/data/apb/apb.yml.j2 new file mode 100644 index 0000000000..0282f004eb --- /dev/null +++ b/lib/ansible/galaxy/data/apb/apb.yml.j2 @@ -0,0 +1,13 @@ +version: 1.0 +name: {{ role_name }} +description: {{ description }} +bindable: False +async: optional +metadata: + displayName: {{ role_name }} +plans: + - name: default + description: This default plan deploys {{ role_name }} + free: True + metadata: {} + parameters: [] diff --git a/lib/ansible/galaxy/data/apb/defaults/main.yml.j2 b/lib/ansible/galaxy/data/apb/defaults/main.yml.j2 new file mode 100644 index 0000000000..3818e64c33 --- /dev/null +++ b/lib/ansible/galaxy/data/apb/defaults/main.yml.j2 @@ -0,0 +1,2 @@ +--- +# defaults file for {{ role_name }} diff --git a/lib/ansible/galaxy/data/container_enabled/files/.git_keep b/lib/ansible/galaxy/data/apb/files/.git_keep similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/files/.git_keep rename to lib/ansible/galaxy/data/apb/files/.git_keep diff --git a/lib/ansible/galaxy/data/container_enabled/handlers/main.yml.j2 b/lib/ansible/galaxy/data/apb/handlers/main.yml.j2 similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/handlers/main.yml.j2 rename to lib/ansible/galaxy/data/apb/handlers/main.yml.j2 diff --git a/lib/ansible/galaxy/data/apb/meta/main.yml.j2 b/lib/ansible/galaxy/data/apb/meta/main.yml.j2 new file mode 100644 index 0000000000..ec42de2574 --- /dev/null +++ b/lib/ansible/galaxy/data/apb/meta/main.yml.j2 @@ -0,0 +1,52 @@ +galaxy_info: + author: {{ author }} + description: {{ description }} + company: {{ company }} + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: {{ issue_tracker_url }} + + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: {{ license }} + + # Optionally specify the branch Galaxy will use when accessing the GitHub + # repo for this role. During role install, if no tags are available, + # Galaxy will use this branch. During import Galaxy will access files on + # this branch. If Travis integration is configured, only notifications for this + # branch will be accepted. Otherwise, in all cases, the repo's default branch + # (usually master) will be used. + #github_branch: + + # + # platforms is a list of platforms, and each platform has a name and a list of versions. + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: + - apb + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/lib/ansible/galaxy/data/apb/playbooks/deprovision.yml.j2 b/lib/ansible/galaxy/data/apb/playbooks/deprovision.yml.j2 new file mode 100644 index 0000000000..a03f79bf83 --- /dev/null +++ b/lib/ansible/galaxy/data/apb/playbooks/deprovision.yml.j2 @@ -0,0 +1,9 @@ +- name: {{ role_name }} playbook to deprovision the application + hosts: localhost + gather_facts: false + connection: local + vars: + apb_action: deprovision + roles: + - role: {{ role_name }} + diff --git a/lib/ansible/galaxy/data/apb/playbooks/provision.yml.j2 b/lib/ansible/galaxy/data/apb/playbooks/provision.yml.j2 new file mode 100644 index 0000000000..d3e122831a --- /dev/null +++ b/lib/ansible/galaxy/data/apb/playbooks/provision.yml.j2 @@ -0,0 +1,9 @@ +- name: {{ role_name }} playbook to provision the application + hosts: localhost + gather_facts: false + connection: local + vars: + apb_action: provision + roles: + - role: {{ role_name }} + diff --git a/lib/ansible/galaxy/data/apb/tasks/main.yml.j2 b/lib/ansible/galaxy/data/apb/tasks/main.yml.j2 new file mode 100644 index 0000000000..a988065059 --- /dev/null +++ b/lib/ansible/galaxy/data/apb/tasks/main.yml.j2 @@ -0,0 +1,2 @@ +--- +# tasks file for {{ role_name }} diff --git a/lib/ansible/galaxy/data/container_enabled/templates/.git_keep b/lib/ansible/galaxy/data/apb/templates/.git_keep similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/templates/.git_keep rename to lib/ansible/galaxy/data/apb/templates/.git_keep diff --git a/lib/ansible/galaxy/data/container_enabled/tests/ansible.cfg b/lib/ansible/galaxy/data/apb/tests/ansible.cfg similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/tests/ansible.cfg rename to lib/ansible/galaxy/data/apb/tests/ansible.cfg diff --git a/lib/ansible/galaxy/data/container_enabled/tests/inventory b/lib/ansible/galaxy/data/apb/tests/inventory similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/tests/inventory rename to lib/ansible/galaxy/data/apb/tests/inventory diff --git a/lib/ansible/galaxy/data/container_enabled/tests/test.yml.j2 b/lib/ansible/galaxy/data/apb/tests/test.yml.j2 similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/tests/test.yml.j2 rename to lib/ansible/galaxy/data/apb/tests/test.yml.j2 diff --git a/lib/ansible/galaxy/data/container_enabled/vars/main.yml.j2 b/lib/ansible/galaxy/data/apb/vars/main.yml.j2 similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/vars/main.yml.j2 rename to lib/ansible/galaxy/data/apb/vars/main.yml.j2 diff --git a/lib/ansible/galaxy/data/container_enabled/.travis.yml b/lib/ansible/galaxy/data/container/.travis.yml similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/.travis.yml rename to lib/ansible/galaxy/data/container/.travis.yml diff --git a/lib/ansible/galaxy/data/container_enabled/README.md b/lib/ansible/galaxy/data/container/README.md similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/README.md rename to lib/ansible/galaxy/data/container/README.md diff --git a/lib/ansible/galaxy/data/container_enabled/defaults/main.yml.j2 b/lib/ansible/galaxy/data/container/defaults/main.yml.j2 similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/defaults/main.yml.j2 rename to lib/ansible/galaxy/data/container/defaults/main.yml.j2 diff --git a/lib/ansible/galaxy/data/container/files/.git_keep b/lib/ansible/galaxy/data/container/files/.git_keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/ansible/galaxy/data/container/handlers/main.yml.j2 b/lib/ansible/galaxy/data/container/handlers/main.yml.j2 new file mode 100644 index 0000000000..3f4c49674d --- /dev/null +++ b/lib/ansible/galaxy/data/container/handlers/main.yml.j2 @@ -0,0 +1,2 @@ +--- +# handlers file for {{ role_name }} diff --git a/lib/ansible/galaxy/data/container_enabled/meta/container.yml.j2 b/lib/ansible/galaxy/data/container/meta/container.yml.j2 similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/meta/container.yml.j2 rename to lib/ansible/galaxy/data/container/meta/container.yml.j2 diff --git a/lib/ansible/galaxy/data/container_enabled/meta/main.yml.j2 b/lib/ansible/galaxy/data/container/meta/main.yml.j2 similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/meta/main.yml.j2 rename to lib/ansible/galaxy/data/container/meta/main.yml.j2 diff --git a/lib/ansible/galaxy/data/container_enabled/tasks/main.yml.j2 b/lib/ansible/galaxy/data/container/tasks/main.yml.j2 similarity index 100% rename from lib/ansible/galaxy/data/container_enabled/tasks/main.yml.j2 rename to lib/ansible/galaxy/data/container/tasks/main.yml.j2 diff --git a/lib/ansible/galaxy/data/container/templates/.git_keep b/lib/ansible/galaxy/data/container/templates/.git_keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/ansible/galaxy/data/container/tests/ansible.cfg b/lib/ansible/galaxy/data/container/tests/ansible.cfg new file mode 100644 index 0000000000..2f74f1b272 --- /dev/null +++ b/lib/ansible/galaxy/data/container/tests/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +inventory=./inventory diff --git a/lib/ansible/galaxy/data/container/tests/inventory b/lib/ansible/galaxy/data/container/tests/inventory new file mode 100644 index 0000000000..ea69cbf122 --- /dev/null +++ b/lib/ansible/galaxy/data/container/tests/inventory @@ -0,0 +1,3 @@ +localhost + + diff --git a/lib/ansible/galaxy/data/container/tests/test.yml.j2 b/lib/ansible/galaxy/data/container/tests/test.yml.j2 new file mode 100644 index 0000000000..224ea3113e --- /dev/null +++ b/lib/ansible/galaxy/data/container/tests/test.yml.j2 @@ -0,0 +1,8 @@ +--- +- hosts: localhost + gather_facts: no + connection: local + tasks: + + # Add tasks and assertions for testing the service here. + diff --git a/lib/ansible/galaxy/data/container/vars/main.yml.j2 b/lib/ansible/galaxy/data/container/vars/main.yml.j2 new file mode 100644 index 0000000000..b0524ec32a --- /dev/null +++ b/lib/ansible/galaxy/data/container/vars/main.yml.j2 @@ -0,0 +1,3 @@ +--- +# vars file for {{ role_name }} + diff --git a/test/units/cli/test_galaxy.py b/test/units/cli/test_galaxy.py index cc44ec1964..b0f9eccdd4 100644 --- a/test/units/cli/test_galaxy.py +++ b/test/units/cli/test_galaxy.py @@ -368,11 +368,41 @@ class TestGalaxyInitDefault(unittest.TestCase, ValidRoleTests): self.assertEqual(metadata.get('galaxy_info', dict()).get('author'), 'your name', msg='author was not set properly in metadata') -class TestGalaxyInitContainerEnabled(unittest.TestCase, ValidRoleTests): +class TestGalaxyInitAPB(unittest.TestCase, ValidRoleTests): @classmethod def setUpClass(cls): - cls.setUpRole('delete_me_container', galaxy_args=['--container-enabled']) + cls.setUpRole('delete_me_apb', galaxy_args=['--type=apb']) + + def test_metadata_apb_tag(self): + with open(os.path.join(self.role_dir, 'meta', 'main.yml'), 'r') as mf: + metadata = yaml.safe_load(mf) + self.assertIn('apb', metadata.get('galaxy_info', dict()).get('galaxy_tags', []), msg='apb tag not set in role metadata') + + def test_metadata_contents(self): + with open(os.path.join(self.role_dir, 'meta', 'main.yml'), 'r') as mf: + metadata = yaml.safe_load(mf) + self.assertEqual(metadata.get('galaxy_info', dict()).get('author'), 'your name', msg='author was not set properly in metadata') + + def test_apb_yml(self): + self.assertTrue(os.path.exists(os.path.join(self.role_dir, 'apb.yml')), msg='apb.yml was not created') + + def test_test_yml(self): + with open(os.path.join(self.role_dir, 'tests', 'test.yml'), 'r') as f: + test_playbook = yaml.safe_load(f) + print(test_playbook) + self.assertEqual(len(test_playbook), 1) + self.assertEqual(test_playbook[0]['hosts'], 'localhost') + self.assertFalse(test_playbook[0]['gather_facts']) + self.assertEqual(test_playbook[0]['connection'], 'local') + self.assertIsNone(test_playbook[0]['tasks'], msg='We\'re expecting an unset list of tasks in test.yml') + + +class TestGalaxyInitContainer(unittest.TestCase, ValidRoleTests): + + @classmethod + def setUpClass(cls): + cls.setUpRole('delete_me_container', galaxy_args=['--type=container']) def test_metadata_container_tag(self): with open(os.path.join(self.role_dir, 'meta', 'main.yml'), 'r') as mf: