我正在尝试使用Ansible来部署到AWS中的两个区域,我现在让它处理一个区域。问题是,我只想执行我的primary_region或secondary_region,这取决于它使用的模板中的参数。
我的main.yaml
- hosts: primary_region
name: Create ECR
tasks:
- name: "Create ECR Repository"
cloudformation:
state: "{{ state }}"
stack_name: "{{ stack_create_ecr.name }}"
profile: "{{ aws_profile }}"
region: "{{ inventory_hostname }}"
template_url: "{{ stack_create_ecr.template_url }}"
template_parameters:
"ansibleFile"
tags:
"{{ stack_create_ecr.tags }}"
tags:
- stack_create_ecr
when: stack_create_ecr.region == "primary_region" <-- This
- hosts: secondary_region
name: Create ECR
tasks:
- name: "Create ECR Repository"
cloudformation:
state: "{{ state }}"
stack_name: "{{ stack_create_ecr.name }}"
profile: "{{ aws_profile }}"
region: "{{ inventory_hostname }}"
template_url: "{{ stack_create_ecr.template_url }}"
template_parameters:
"ansibleFile"
tags:
"{{ stack_create_ecr.tags }}"
tags:
- stack_create_ecr
when: stack_create_ecr.region == "secondary_region" <-- This我使用的模板stack_create_ecr.yaml
stack_create_ecr:
name: cloudFormationTemplateNameOmitted
template_url: S3BucketUrl
parameters:
RepoName: EcrRepoName
DevName: cloud-dev
tags:
ansible_playbook: "{{ ansible_playbook_tag }}"
region: primary_region <-- This is what I'm trying to use每次我试着运行我的剧本,我都会得到msg: 'argument template_parameters is of type <class ''str''> and we were unable to convert to dict: dictionary requested, could not parse JSON or key=value'
我尝试过各种各样的东西,从在when条件下将引号放在字符串周围。好像什么都没用,我做错什么了?
发布于 2022-07-29 07:33:39
你好像用了template_parameters道具。它应该是一个映射,但是您提供了一个字符串:
template_parameters:
PropName: "ansibleFile"https://stackoverflow.com/questions/73159390
复制相似问题