Add a new strategy filtering tasks
Ideally Ansible should allow (from a playbook) to run only part of a role thanks to its tags (like the --skip-tags or --tags from the cli). But it's not possible now. This code is a PoC code for introducing a kind of filtering, which basically skips tasks containing the word "config". If you are building lxc images ("artifacts") of a role, you probably don't want to run all the tasks in the role, and don't want to run the handler tasks (because they start software for example). This also addresses it. To use this work, just include strategy: artifacting in your play. Change-Id: I006bc640c6563c959ceb835ddf5bef8d25dd7517
This commit is contained in:
parent
1b0f9f1b99
commit
655d777734
35
strategy/artifacting.py
Normal file
35
strategy/artifacting.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Copyright 2017, Rackspace US, Inc.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
import os
|
||||
|
||||
import linear
|
||||
|
||||
|
||||
class StrategyModule(linear.StrategyModule):
|
||||
def _queue_task(self, host, task, task_vars, play_context):
|
||||
"""Wipe the notification system and return for config tasks."""
|
||||
task.notify = None
|
||||
skip_tags = os.environ.get('OS_ANSIBLE_SKIP_TAGS', 'config')
|
||||
skip_tags = skip_tags.split(',')
|
||||
if any([True for i in skip_tags if i in task.tags]):
|
||||
return
|
||||
else:
|
||||
return super(StrategyModule, self)._queue_task(
|
||||
host,
|
||||
task,
|
||||
task_vars,
|
||||
play_context
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user