我无法在terraform my-vpc输出中找到vpc_id
和public_subnet.0
。
每次我下命令的时候:
ansible-playbook playbook1.yml -e "vpc_id=$(terraform output my-vpc.vpc_id) vpc_subnet_id=$(terraform output my-vpc.public_subnets.0)" -vvv
但它打印地形输出my-vpc
-bash-4.2$ terraform output my-vpc
{
"azs" = tolist([
"eu-west-1a",
"eu-west-1b",
"eu-west-1c",
])
"cgw_arns" = []
"cgw_ids" = []
"database_internet_gateway_route_id" = ""
"database_ipv6_egress_route_id" = ""
"database_nat_gateway_route_ids" = []
"database_network_acl_arn" = ""
"database_network_acl_id" = ""
"database_route_table_association_ids" = [
"rtbassoc-0c0a897cce6cbac74",
"rtbassoc-02c2f605eb9988418",
"rtbassoc-0b14ef189c6c39da5",
]
"database_route_table_ids" = [
"rtb-038a86ea7eef50de1",
]
"database_subnet_arns" = [
"arn:aws:ec2:eu-west-1:008421212484:subnet/subnet-0ef73bc4e91557920",
"arn:aws:ec2:eu-west-1:008421212484:subnet/subnet-0f044d3b21cecbca6",
"arn:aws:ec2:eu-west-1:008421212484:subnet/subnet-042312717d7ed4fe6",
]
"database_subnet_group" = "my-vpc"
"database_subnet_group_name" = "my-vpc"
"database_subnets" = [
"subnet-0ef73bc4e91557920",
"subnet-0f044d3b21cecbca6",
"subnet-042312717d7ed4fe6",
]
"database_subnets_cidr_blocks" = tolist([
"10.0.21.0/24",
"10.0.22.0/24",
"10.0.23.0/24",
])
"database_subnets_ipv6_cidr_blocks" = tolist([])
"default_network_acl_id" = "acl-08f647113ea769f4f"
"default_route_table_id" = "rtb-0b55d9919c1133316"
"default_security_group_id" = "sg-050c394121822118f"
"default_vpc_arn" = ""
"default_vpc_cidr_block" = ""
"default_vpc_default_network_acl_id" = ""
"default_vpc_default_route_table_id" = ""
"default_vpc_default_security_group_id" = ""
"default_vpc_enable_dns_hostnames" = ""
"default_vpc_enable_dns_support" = ""
"default_vpc_id" = ""
"default_vpc_instance_tenancy" = ""
"default_vpc_main_route_table_id" = ""
"dhcp_options_id" = ""
"egress_only_internet_gateway_id" = ""
"elasticache_network_acl_arn" = ""
"elasticache_network_acl_id" = ""
"elasticache_route_table_association_ids" = []
"elasticache_route_table_ids" = [
"rtb-0bbad3836a81d51cd",
]
"elasticache_subnet_arns" = []
"elasticache_subnet_group" = ""
"elasticache_subnet_group_name" = ""
"elasticache_subnets" = []
"elasticache_subnets_cidr_blocks" = tolist([])
"elasticache_subnets_ipv6_cidr_blocks" = tolist([])
"igw_arn" = "arn:aws:ec2:eu-west-1:008421212484:internet-gateway/igw-006457c32d869d138"
"igw_id" = "igw-006457c32d869d138"
"intra_network_acl_arn" = ""
"intra_network_acl_id" = ""
"intra_route_table_association_ids" = []
"intra_route_table_ids" = []
"intra_subnet_arns" = []
"intra_subnets" = []
"intra_subnets_cidr_blocks" = tolist([])
"intra_subnets_ipv6_cidr_blocks" = tolist([])
"name" = "my-vpc"
"nat_ids" = [
"eipalloc-0a8b17a3d8101a5a0",
]
"nat_public_ips" = tolist([
"18.200.43.46",
])
"natgw_ids" = [
"nat-0c1f640cfa6bc1b9c",
]
"outpost_network_acl_arn" = ""
"outpost_network_acl_id" = ""
"outpost_subnet_arns" = []
"outpost_subnets" = []
"outpost_subnets_cidr_blocks" = tolist([])
"outpost_subnets_ipv6_cidr_blocks" = tolist([])
"private_ipv6_egress_route_ids" = []
"private_nat_gateway_route_ids" = [
"r-rtb-0bbad3836a81d51cd1080289494",
]
"private_network_acl_arn" = ""
"private_network_acl_id" = ""
"private_route_table_association_ids" = [
"rtbassoc-046f37259950a7f95",
"rtbassoc-0be769cfe2ebd6034",
"rtbassoc-03dab517c9aa2789c",
]
"private_route_table_ids" = [
"rtb-0bbad3836a81d51cd",
]
"private_subnet_arns" = [
"arn:aws:ec2:eu-west-1:008421212484:subnet/subnet-038ffd52b102ad03d",
"arn:aws:ec2:eu-west-1:008421212484:subnet/subnet-07fff3a676d8792b7",
"arn:aws:ec2:eu-west-1:008421212484:subnet/subnet-09d7264428c109220",
]
"private_subnets" = [
"subnet-038ffd52b102ad03d",
"subnet-07fff3a676d8792b7",
"subnet-09d7264428c109220",
]
"private_subnets_cidr_blocks" = tolist([
"10.0.11.0/24",
"10.0.12.0/24",
"10.0.13.0/24",
])
"private_subnets_ipv6_cidr_blocks" = tolist([])
"public_internet_gateway_ipv6_route_id" = ""
"public_internet_gateway_route_id" = "r-rtb-095c4a905b733cb521080289494"
"public_network_acl_arn" = ""
"public_network_acl_id" = ""
"public_route_table_association_ids" = [
"rtbassoc-08b42ea2c1b00f82c",
"rtbassoc-06d913cc918b08721",
"rtbassoc-04437e6c3b6deea45",
]
"public_route_table_ids" = [
"rtb-095c4a905b733cb52",
]
"public_subnet_arns" = [
"arn:aws:ec2:eu-west-1:008421212484:subnet/subnet-08dbadd83e2dfea89",
"arn:aws:ec2:eu-west-1:008421212484:subnet/subnet-07b49f530d35a3899",
"arn:aws:ec2:eu-west-1:008421212484:subnet/subnet-057153ea6183d363f",
]
"public_subnets" = [
"subnet-08dbadd83e2dfea89",
"subnet-07b49f530d35a3899",
"subnet-057153ea6183d363f",
]
"public_subnets_cidr_blocks" = tolist([
"10.0.1.0/24",
"10.0.2.0/24",
"10.0.3.0/24",
])
"public_subnets_ipv6_cidr_blocks" = tolist([])
"redshift_network_acl_arn" = ""
"redshift_network_acl_id" = ""
"redshift_public_route_table_association_ids" = []
"redshift_route_table_association_ids" = []
"redshift_route_table_ids" = tolist([
"rtb-0bbad3836a81d51cd",
])
"redshift_subnet_arns" = []
"redshift_subnet_group" = ""
"redshift_subnets" = []
"redshift_subnets_cidr_blocks" = tolist([])
"redshift_subnets_ipv6_cidr_blocks" = tolist([])
"this_customer_gateway" = {}
"vgw_arn" = ""
"vgw_id" = ""
"vpc_arn" = "arn:aws:ec2:eu-west-1:008421212484:vpc/vpc-081b13e816e14214c"
"vpc_cidr_block" = "10.0.0.0/16"
"vpc_enable_dns_hostnames" = true
"vpc_enable_dns_support" = true
"vpc_flow_log_cloudwatch_iam_role_arn" = ""
"vpc_flow_log_destination_arn" = ""
"vpc_flow_log_destination_type" = "cloud-watch-logs"
"vpc_flow_log_id" = ""
"vpc_id" = "vpc-081b13e816e14214c"
"vpc_instance_tenancy" = "default"
"vpc_ipv6_association_id" = ""
"vpc_ipv6_cidr_block" = ""
"vpc_main_route_table_id" = "rtb-0b55d9919c1133316"
"vpc_owner_id" = "008421212484"
"vpc_secondary_cidr_blocks" = tolist([])
}
我在尝试:
- 不同的命名和路径。
- Jenkins用户权限。
- 输出的目的地。
2条答案
按热度按时间lf5gs5x21#
输出应是人类可读的:
默认情况下,
terraform output
命令以可读格式显示,该格式可以随时间更改以提高清晰度。这意味着使用通常的terraform语法获取值并不容易,您需要使用
jq
[1]这样的工具。因此,在您的示例中,它必须是这样的:接着是:
我的Ansible技能有点生疏了,可能有更好的方法,但这应该能让你开始。
[1] https://developer.hashicorp.com/terraform/cli/commands/output#use-in-automation
envsm3lx2#
感谢我同事的支持我们找到了解决办法:jq ;)