Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
key: 'test key'
value: 'test value'
when: ara_record
Where `` is a random integer generated each time this
function is called.
Set the `complete` parameter to `False` to simulate an
aborted Ansible run.
Set the `gathered_facts` parameter to `False` to simulate a run with no
facts gathered.
Set the `ara_record` parameter to `True` to simulate a run with an
ara_record task.
'''
playbook = m.Playbook(path='testing.yml')
playbook_file = m.File(path=playbook.path,
playbook=playbook,
is_playbook=True)
play = m.Play(playbook=playbook, name='test play')
host = m.Host(name='host-%04d' % random.randint(0, 9999),
playbook=playbook)
if ara_record:
task = m.Task(play=play, playbook=playbook, action='ara_record')
msg = 'Data recorded in ARA for this playbook.'
else:
task = m.Task(play=play, playbook=playbook, action='test-action')
msg = 'This is a test'
result = m.TaskResult(task=task, status='ok', host=host, result=msg)
def tearDown(self):
m.db.session.remove()
m.db.drop_all()
def take_action(self, args):
if not args.playbook_id and not args.incomplete:
raise RuntimeError('Nothing to delete')
if args.playbook_id and args.incomplete:
raise RuntimeError('You may not use --incomplete with '
'a list of playbooks')
if args.incomplete:
pids = (playbook.id for playbook in
models.Playbook.query.filter_by(complete=False))
else:
pids = []
for pid in args.playbook_id:
res = models.Playbook.query.get(pid)
if res is None:
if args.ignore_errors:
self.log.warning('Playbook %s does not exist '
'(ignoring)' % pid)
else:
raise RuntimeError('Playbook %s does not exist' % pid)
else:
pids.append(pid)
for pid in pids:
self.log.warning('deleting playbook %s', pid)
playbook = models.Playbook.query.get(pid)
db.session.delete(playbook)
db.session.commit()
def take_action(self, args):
plays = (models.Play.query
.join(models.Playbook)
.filter(models.Play.playbook_id == models.Playbook.id)
.order_by(models.Play.time_start, models.Play.sortkey))
if args.playbook:
plays = plays.filter(models.Play.playbook_id == args.playbook)
return [[field.name for field in LIST_FIELDS],
[[field(play) for field in LIST_FIELDS]
for play in plays]]
def ctx_add_nav_data():
"""
Returns standard data that will be available in every template view.
"""
try:
models.Playbook.query.one()
empty_database = False
except models.MultipleResultsFound:
empty_database = False
except models.NoResultFound:
empty_database = True
# Get python version info
major, minor, micro, release, serial = sys.version_info
return dict(ara_version=ara_release,
ansible_version=ansible_version,
python_version="{0}.{1}".format(major, minor),
empty_database=empty_database)