Commit f9d40604 authored by Alan Rominger's avatar Alan Rominger Committed by GitHub

Merge pull request #326 from AlanCoding/is_name_wrk

All inv src loops do name replacement, workflow docs
parents 09fe2a9a 1de7e094
# Branch that has deeply nested content removed going to schema B
- job_template: workflow JT
failure_nodes:
- inventory_source: tower script1 (workflow demo
success_nodes:
- project: Ansible Examples
always_nodes:
- job_template: workflow JT
success_nodes:
- job_template: workflow JT
# Branch that is modified going to schema B
- job_template: workflow JT2
failure_nodes:
- job_template: workflow JT2
- job_template: workflow JT
success_nodes:
- job_template: workflow JT2
- job_template: workflow JT
# Branch that is deleted going to schema B
- project: Ansible Examples
always_nodes:
- inventory_source: tower script1 (workflow demo
- inventory_source: tower script2 (workflow demo
# Branch that has deeply nested content removed going to schema B
- job_template: workflow JT
failure_nodes:
- inventory_source: tower script1 (workflow demo
success_nodes:
- project: Ansible Examples
always_nodes:
- job_template: workflow JT
# Branch that is modified going to schema B
- job_template: workflow JT2
failure_nodes:
- inventory_source: tower script1 (workflow demo
- inventory_source: tower script2 (workflow demo
success_nodes:
- project: Ansible Examples
- job_template: workflow JT
- job_template: workflow JT
failure:
- inventory_source: tower script1 (workflow demo
success:
- project: Ansible Examples
always:
- job_template: workflow JT
success:
- job_template: workflow JT
\ No newline at end of file
- job_template: workflow JT
\ No newline at end of file
......@@ -37,8 +37,6 @@ echo " current configuration settings:"
echo $hostval
echo $userval
tower-cli config verify_ssl false
echo "Tower-CLI DATA FAKER: creating orgs and teams"
# Data regarding Hyrule Ventures was taken from
# https://github.com/jsmartin/tower_populator
......
#!/usr/bin/env python
import json
inv = {
'_meta': {
'hostvars': {}
},
'hosts': []
}
for num in range(0, 3):
host = u"host-%0.2d" % num
inv['hosts'].append(host)
inv['_meta']['hostvars'][host] = dict(ansible_ssh_host='127.0.0.1', ansible_connection='local')
print(json.dumps(inv, indent=2))
# Copyright 2017, Ansible by Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This bash script can populate an instance of Ansible Tower with
# fake data, using the command line interface (tower-cli) to do so.
echo " "
echo " == Tower-CLI WORKFLOW DEMO == "
echo " "
echo "current location: ${BASH_SOURCE%/*}"
tower-cli organization create --name="Default"
tower-cli project create --name="Ansible Examples" --scm-type=git --scm-url="https://github.com/ansible/ansible-examples" --wait
tower-cli project create --name="Ansible Examples2" --scm-type=git --scm-url="https://github.com/ansible/ansible-examples" --wait
tower-cli inventory create --name="workflow demo" --organization=Default
tower-cli inventory_script create --name="example inv script" --organization="Default" --script="@${BASH_SOURCE%/*}/inventory_script_example.py"
# Note that these 2 groups need to have distinct names without one starting with the other
tower-cli group create --name="tower script1" --inventory="workflow demo" --source="custom" --source-script="example inv script"
tower-cli group create --name="tower script2" --inventory="workflow demo" --source="custom" --source-script="example inv script"
tower-cli inventory create --name="localhost"
tower-cli host create --inventory="localhost" --name="localhost" --variables='{"connection": "local", "ansible_host": "localhost"}'
tower-cli credential create --name="Local SSH" --kind=ssh --organization="Default" --ssh-key-data="${BASH_SOURCE%/*}/insecure_private_key"
tower-cli job_template create --name="workflow JT" --inventory="localhost" --machine-credential="Local SSH" --project="Ansible Examples" --playbook="language_features/loop_nested.yml"
tower-cli job_template create --name="workflow JT2" --inventory="localhost" --machine-credential="Local SSH" --project="Ansible Examples" --playbook="language_features/loop_nested.yml"
# Create the WFJT resource itself
tower-cli workflow create --name="workflow demo" --organization="Default"
echo ''
echo ' -- application of simple schema --'
tower-cli workflow schema "workflow demo" "@${BASH_SOURCE%/*}/data/schema_simple.yml"
echo ''
echo ' -- application of tiny schema --'
tower-cli workflow schema "workflow demo" "@${BASH_SOURCE%/*}/data/schema_tiny.yml"
echo ''
echo ' -- application of schema a --'
tower-cli workflow schema "workflow demo" "@${BASH_SOURCE%/*}/data/schema_a.yml"
echo ''
echo ' -- application of schema a --'
tower-cli workflow schema "workflow demo" "@${BASH_SOURCE%/*}/data/schema_b.yml"
......@@ -137,13 +137,6 @@ class Related(click.types.ParamType):
debug.log('The %s field is given as a name; '
'looking it up.' % param.name, header='details')
lookup_data = {resource.identity[-1]: value}
# Special case to look up inventory sources by partial name
# TODO: Remove with v1 deprecation
if (self.resource_name == 'inventory_source' and
not resource._is_full_v1_name(value)):
lookup_data = {
"query": [('name__startswith', value)]
}
rel = resource.get(**lookup_data)
except exc.MultipleResults as ex:
raise exc.MultipleRelatedError(
......
......@@ -58,6 +58,19 @@ class Resource(models.MonitorableResource):
def _is_full_v1_name(self, name):
return bool(re.match(r'^.+\s\(.+\s-\s\d+\)$', name))
def read(self, pk=None, fail_on_no_results=False,
fail_on_multiple_results=False, **kwargs):
# Special case to look up inventory sources by partial name
# TODO: Remove with v1 deprecation
if (kwargs.get('name', None) and not kwargs.get('group', None) and
not self._is_full_v1_name(kwargs['name'])):
kwargs.setdefault('query', [])
kwargs['query'] += [('name__startswith', kwargs['name'])]
kwargs.pop('name')
return super(Resource, self).read(
pk, fail_on_no_results=fail_on_no_results,
fail_on_multiple_results=fail_on_multiple_results, **kwargs)
@click.argument('inventory_source', type=types.Related('inventory_source'))
@click.option('--monitor', is_flag=True, default=False,
help='If sent, immediately calls `monitor` on the newly '
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment