Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible 如何从include_任务返回结果_Ansible - Fatal编程技术网

Ansible 如何从include_任务返回结果

Ansible 如何从include_任务返回结果,ansible,Ansible,昨天开始学习ansible,所以我相信我可能会在这里遇到XY问题,但仍然 主要yml: - hosts: localhost vars_files: [ "users.yml" ] tasks: - name: manage instances #include_tasks: create_instance.yml include_tasks: inhabit_instance.yml with_dict: "{{users}}"

昨天开始学习ansible,所以我相信我可能会在这里遇到XY问题,但仍然

主要yml:

- hosts: localhost

  vars_files:
    [ "users.yml" ]
  tasks:
    - name: manage instances
      #include_tasks: create_instance.yml
      include_tasks: inhabit_instance.yml
      with_dict: "{{users}}"
      register: res
    - name: print
      debug: msg="{{res.results}}"
reshibit_instance.yml:

- name: Get instance info for {{ item.key }}
  ec2_instance_facts:
    profile: henryaws
    filters:
      "tag:name": "{{item.key}}"
      instance-state-name: running
  register: ec2
- name: print
  debug:
    msg: "IP: {{ec2.instances.0.public_ip_address}}"
- name: Get instance info for {{ item.key }}
  ec2_instance_facts:
    profile: henryaws
    filters:
      "tag:name": "{{item.key}}"
      instance-state-name: running
  register: ec2
- name: update
  set_fact:
    ec_results: "{{ ec_results|combine({ item.key: ec2.instances.0.public_ip_address }) }}"

这就是我想要的顶级IP。还并没有找到关于include块返回值的任何信息…

好吧,我找到了一些适合我的方法,也许它甚至是规范的

main.yml:

- hosts: localhost

  vars_files:
    [ "users.yml" ]
  vars: 
    ec_results: {}
  tasks:
    - name: manage instances
      #include_tasks: create_instance.yml
      include_tasks: inhabit_instance.yml
      with_dict: "{{users}}"
      register: res
reshibit_instance.yml:

- name: Get instance info for {{ item.key }}
  ec2_instance_facts:
    profile: henryaws
    filters:
      "tag:name": "{{item.key}}"
      instance-state-name: running
  register: ec2
- name: print
  debug:
    msg: "IP: {{ec2.instances.0.public_ip_address}}"
- name: Get instance info for {{ item.key }}
  ec2_instance_facts:
    profile: henryaws
    filters:
      "tag:name": "{{item.key}}"
      instance-state-name: running
  register: ec2
- name: update
  set_fact:
    ec_results: "{{ ec_results|combine({ item.key: ec2.instances.0.public_ip_address }) }}"

它拯救了我的一天。非常感谢。