How can Ansible “register” in a variable the result of including a playbook?

前端 未结 2 1254
囚心锁ツ
囚心锁ツ 2020-12-10 11:39

How can an Ansible playbook register in a variable the result of including another playbook?

For example, would the following register the result of executing

2条回答
  •  不知归路
    2020-12-10 12:17

    I was able to do this by passing a variable name as a variable to be used in the task. I included my main.yaml and included cgw.yaml files below.

    main.yaml:

    - name: Create App A CGW
      include: cgw.yaml
      vars:
        bgp_asn: "{{ asn_spoke }}"
        ip_address: "{{ eip_app_a.public_ip }}"
        name: cgw-app-a
        region: "{{ aws_region }}"
        aws_access_key: "{{ ec2_access_key }}"
        aws_secret_key: "{{ ec2_secret_key }}"
        register: cgw_app_a
    

    cgw.yaml:

    - name: "{{ name }}"
      ec2_customer_gateway:
        bgp_asn: "{{ bgp_asn }}"
        ip_address: "{{ ip_address }}"
        name: "{{ name }}"
        region: "{{ region }}"
        aws_access_key: "{{ aws_access_key }}"
        aws_secret_key: "{{ aws_secret_key }}"
      register: "{{ register }}"
    

提交回复
热议问题