Created
May 12, 2016 20:08
-
-
Save dmsimard/468d838c56d878a9e6ff3a3975dbf78e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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