Skip to content

Instantly share code, notes, and snippets.

@dmsimard
Created May 12, 2016 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmsimard/468d838c56d878a9e6ff3a3975dbf78e to your computer and use it in GitHub Desktop.
Save dmsimard/468d838c56d878a9e6ff3a3975dbf78e to your computer and use it in GitHub Desktop.
tasks = (models.Task.query
.join(models.Play)
.join(models.Playbook)
.filter(models.Task.playbook_id == models.Playbook.id)
.filter(models.Task.play_id == models.Play.id))
for task in tasks:
print(task.playbook_path)
class Task(db.Model, TimedEntity):
'''The `Task` class represents a single task defined in an Ansible
playbook.
`Task` entities have the following relationships:
- `playbook` -- the playbook containing thist ask (via the `tasks`
relationship defined by `Playbook`)
- `play` -- the play containing this task (via the `tasks`
relationship defined by `Play`)
- `task_results` -- a list of results for each host targeted by
this task.
'''
__tablename__ = 'tasks'
id = db.Column(db.String(36), primary_key=True, nullable=False,
default=mkuuid)
playbook_id = db.Column(db.String(36), db.ForeignKey('playbooks.id'))
play_id = db.Column(db.String(36), db.ForeignKey('plays.id'))
name = db.Column(db.Text)
action = db.Column(db.Text)
path = db.Column(db.Text)
lineno = db.Column(db.Integer)
is_handler = db.Column(db.Boolean)
time_start = db.Column(db.DateTime, default=datetime.now)
time_end = db.Column(db.DateTime)
task_results = db.relationship('TaskResult', backref='task',
lazy='dynamic')
def __repr__(self):
return '<Task %r>' % self.name
@property
def playbook_path(self):
return getattr(self.playbook, "path")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment