Add APB role_type to ansible-galaxy init (#36789)
* Add APB role_type to ansible-galaxy init * Add handlers scaffolding * Fix shippable errors by setting default * Add unit tests and fix shippable * Updates init description
This commit is contained in:
parent
a10df8b0b5
commit
90943a3362
33 changed files with 234 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
26
lib/ansible/galaxy/data/apb/.travis.yml
Normal file
26
lib/ansible/galaxy/data/apb/.travis.yml
Normal file
|
@ -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/
|
8
lib/ansible/galaxy/data/apb/Dockerfile.j2
Normal file
8
lib/ansible/galaxy/data/apb/Dockerfile.j2
Normal file
|
@ -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
|
21
lib/ansible/galaxy/data/apb/Makefile.j2
Normal file
21
lib/ansible/galaxy/data/apb/Makefile.j2
Normal file
|
@ -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
|
||||
|
38
lib/ansible/galaxy/data/apb/README.md
Normal file
38
lib/ansible/galaxy/data/apb/README.md
Normal file
|
@ -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).
|
13
lib/ansible/galaxy/data/apb/apb.yml.j2
Normal file
13
lib/ansible/galaxy/data/apb/apb.yml.j2
Normal file
|
@ -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: []
|
2
lib/ansible/galaxy/data/apb/defaults/main.yml.j2
Normal file
2
lib/ansible/galaxy/data/apb/defaults/main.yml.j2
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# defaults file for {{ role_name }}
|
52
lib/ansible/galaxy/data/apb/meta/main.yml.j2
Normal file
52
lib/ansible/galaxy/data/apb/meta/main.yml.j2
Normal file
|
@ -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.
|
9
lib/ansible/galaxy/data/apb/playbooks/deprovision.yml.j2
Normal file
9
lib/ansible/galaxy/data/apb/playbooks/deprovision.yml.j2
Normal file
|
@ -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 }}
|
||||
|
9
lib/ansible/galaxy/data/apb/playbooks/provision.yml.j2
Normal file
9
lib/ansible/galaxy/data/apb/playbooks/provision.yml.j2
Normal file
|
@ -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 }}
|
||||
|
2
lib/ansible/galaxy/data/apb/tasks/main.yml.j2
Normal file
2
lib/ansible/galaxy/data/apb/tasks/main.yml.j2
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# tasks file for {{ role_name }}
|
0
lib/ansible/galaxy/data/container/files/.git_keep
Normal file
0
lib/ansible/galaxy/data/container/files/.git_keep
Normal file
2
lib/ansible/galaxy/data/container/handlers/main.yml.j2
Normal file
2
lib/ansible/galaxy/data/container/handlers/main.yml.j2
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# handlers file for {{ role_name }}
|
0
lib/ansible/galaxy/data/container/templates/.git_keep
Normal file
0
lib/ansible/galaxy/data/container/templates/.git_keep
Normal file
2
lib/ansible/galaxy/data/container/tests/ansible.cfg
Normal file
2
lib/ansible/galaxy/data/container/tests/ansible.cfg
Normal file
|
@ -0,0 +1,2 @@
|
|||
[defaults]
|
||||
inventory=./inventory
|
3
lib/ansible/galaxy/data/container/tests/inventory
Normal file
3
lib/ansible/galaxy/data/container/tests/inventory
Normal file
|
@ -0,0 +1,3 @@
|
|||
localhost
|
||||
|
||||
|
8
lib/ansible/galaxy/data/container/tests/test.yml.j2
Normal file
8
lib/ansible/galaxy/data/container/tests/test.yml.j2
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
connection: local
|
||||
tasks:
|
||||
|
||||
# Add tasks and assertions for testing the service here.
|
||||
|
3
lib/ansible/galaxy/data/container/vars/main.yml.j2
Normal file
3
lib/ansible/galaxy/data/container/vars/main.yml.j2
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
# vars file for {{ role_name }}
|
||||
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue