我已经看到了如何在ansible playbook中的任务中注册变量,然后在同一playbook中的其他地方使用这些变量,但是您是否可以在包含的playbook中注册变量,然后在原始playbook中访问这些变量?
以下是我试图实现的目标:
这是我的主要策略:
- include: sub-playbook.yml job_url="http://some-jenkins-job"
- hosts: localhost
roles:
- some_rolesub-playbook.yml
---
- hosts: localhost
tasks:
- name: Collect info from Jenkins Job
script: whatever.py --url "{{ job_url }}"
register: jenkins_artifacts如果可能的话,我希望能够以main_playbook格式访问jenkins_artifacts结果。我知道您可以从同一行动手册中的其他主机访问它:"{{ hostvars['localhost']['jenkins_artifacts'].stdout_lines }}"
跨攻略共享的想法是相同的吗?
发布于 2017-05-09 21:53:57
我不明白这个问题是关于什么的。只需使用变量名jenkins_artifacts
- include: sub-playbook.yml job_url="http://some-jenkins-job"
- hosts: localhost
debug:
var: jenkins_artifacts发布于 2019-04-17 20:12:48
这可能看起来很复杂,但我喜欢在我的行动手册中这样做:
rc定义包含返回值的变量的名称
ar将参数提供给包含任务
master.yml:
- name: verify_os
include_tasks: "verify_os/main.yml"
vars:
verify_os:
rc: "isos_present"
ar:
image: "{{ os.ar.to_os }}"验证_os/main.yml:
---
- name: check image on device
ios_command:
commands:
- "sh bootflash: | inc {{ verify_os.ar.image }}"
register: image_check
- name: check if available
shell: "printf '{{ image_check.stdout_lines[0][0] }}\n' | grep {{ verify_os.ar.image }} | wc -l"
register: image_available
delegate_to: localhost
- set_fact: { "{{ verify_os.rc }}": "{{ true if image_available.stdout == '1' else false }}" } ..。
我现在可以在master.yml中的任何地方使用isos_present变量来访问返回值。
https://stackoverflow.com/questions/43869489
复制相似问题