【问题标题】:Is there a more elegant way to access Job Number during runtime?有没有更优雅的方式在运行时访问作业编号?
【发布时间】:2020-01-27 19:17:14
【问题描述】:

我正在尝试访问工作编号,以便通过电子邮件发送指向工作塔日志的链接。它必须在 playbook 中具有访问权限,并且在运行时可用。事实证明,这非常困难,因为 ansible Tower 本身没有此功能。这是调用我的剧本的脚本的一部分:

#Stores the output of the job
tmp = "/tmp/runTowerJob"+str(rand(0,1))
#Stores the input for the job
extravars = " ".join([x+'='+inputDic[x] for x in inputDic])
cmd = 'tower-cli job launch --job-template=' + migration_template + ' --inventory=' + migration_inventory
#Launch first job
system(cmd + ' --extra-vars "' + extravars + '" > ' + tmp + ' 2> /dev/null')
jobNum = open(tmp).read().split('\n')[-3].split(' ')[0]
jobURL = 'https://tower.companyname.ca/#/jobs/playbook/' + jobNum
#Append the real job URL to the parameter file
extravars += ' jobURL=' + jobURL

cmd = 'tower-cli job launch --job-template=' + recordJob_template + ' --inventory=' + recordJob_inventory
cmd = cmd + ' --extra-vars="' + extravars + '" > /dev/null 2> /dev/null'
#Launch second job
system(cmd)

Extravars 包含剧本使用的参数集。只有调用真正的作业后才能访问作业号。第二个作业使用 JobURL 创建一个文本文件。真正的作业将访问该文件以读取其作业 URL,然后将其删除。

这显然是不理想的,会产生很多不可见的依赖关系并且难以构建。有没有更好的办法? Ansible-Tower 中是否有我可能看过的原生功能?

【问题讨论】:

    标签: ansible yaml ansible-awx ansible-tower


    【解决方案1】:

    事实证明,您可以在剧本中的任何位置调用 {{ tower_job_id }} 并且它会起作用!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      相关资源
      最近更新 更多