访问ansible中的寄存器变量值时出错



我试图在另一个任务中访问寄存器变量值,但我遇到了一个错误,甚至知道我可能会犯错误,但无法解决。我将感谢你的帮助。我的代码是:

hosts: localhost
connection: local
gather_facts: false
tasks:
- ec2_vpc_net:
name: Module_dev2
cidr_block: 10.10.0.0/16
region: us-east-1
tags:
module: ec2_vpc_net
this: works
tenancy: default
register: vpc_v
- name: show the VPC info
debug: 
var: vpc_v
- ec2_vpc_igw:
vpc_id: "{{ vpc_v.stdout.id }}"
state: present
register: igw

我得到的错误是

TASK [ec2_vpc_igw] ***************************************************************************************************************************
task path: /home/kamaljit/Desktop/v3/playbooks/vpc_cr.yaml:20
fatal: [localhost]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'id'nnThe error appears to be in '/home/kamaljit/Desktop/v3/playbooks/vpc_cr.yaml': line 20, column 7, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nnn    - ec2_vpc_igw:n      ^ heren"
}
---
- hosts: localhost
connection: local
gather_facts: false
tasks:
- ec2_vpc_net:
name: Module_dev2
cidr_block: 10.10.0.0/16
region: us-east-1
tags:
module: ec2_vpc_net
this: works
tenancy: default
register: vpc_v
- name: show the VPC info
debug: 
var: vpc_v
- ec2_vpc_igw:
vpc_id: "{{ vpc_v.vpc.id }}"
state: present
region: us-east-1
register: igw

代码正确吗

寄存器变量可以是variable_name.module.attribute。感谢

最新更新