Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
ctx = dict(
def get_or_create_file(self, path):
try:
if self.playbook.id:
file_ = (models.File.query
.filter_by(path=path)
.filter_by(playbook_id=self.playbook.id)
.one())
return file_
except models.NoResultFound:
pass
file_ = models.File(path=path, playbook=self.playbook)
db.session.add(file_)
db.session.commit()
try:
with open(path, 'r') as fd:
data = fd.read()
sha1 = models.content_sha1(data)
content = models.FileContent.query.get(sha1)
if content is None:
content = models.FileContent(content=data)
file_.content = content
except IOError:
log.warning('failed to open %s for reading', path)
def get_or_create_file(self, path):
try:
if self.playbook.id:
file_ = (models.File.query
.filter_by(path=path)
.filter_by(playbook_id=self.playbook.id)
.one())
return file_
except models.NoResultFound:
pass
file_ = models.File(path=path, playbook=self.playbook)
db.session.add(file_)
db.session.commit()
try:
with open(path, 'r') as fd:
data = fd.read()
sha1 = models.content_sha1(data)
content = models.FileContent.query.get(sha1)
if content is None:
content = models.FileContent(content=data)
file_.content = content
except IOError:
LOG.warn('failed to open %s for reading', path)
def index():
"""
This is not served anywhere in the web application.
It is used explicitly in the context of generating static files since
flask-frozen requires url_for's to crawl content.
url_for's are not used with file.show_file directly and are instead
dynamically generated through javascript for performance purposes.
"""
if current_app.config['ARA_PLAYBOOK_OVERRIDE'] is not None:
override = current_app.config['ARA_PLAYBOOK_OVERRIDE']
files = (models.File.query
.filter(models.File.playbook_id.in_(override)))
else:
files = models.File.query.all()
return render_template('file_index.html', files=files)
def file(self):
return (self.files
.filter(File.playbook_id == self.id)
.filter(File.is_playbook)).one()
def index():
"""
This is not served anywhere in the web application.
It is used explicitly in the context of generating static files since
flask-frozen requires url_for's to crawl content.
url_for's are not used with file.show_file directly and are instead
dynamically generated through javascript for performance purposes.
"""
if current_app.config['ARA_PLAYBOOK_OVERRIDE'] is not None:
override = current_app.config['ARA_PLAYBOOK_OVERRIDE']
files = (models.File.query
.filter(models.File.playbook_id.in_(override)))
else:
files = models.File.query.all()
return render_template('file_index.html', files=files)
def take_action(self, args):
file_ = models.File.query.get(args.file)
if file_ is None:
raise RuntimeError('File %s could not be found' % args.file)
return [[field.name for field in FIELDS],
[field(file_) for field in FIELDS]]