首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于模板参数的条件任务失败

基于模板参数的条件任务失败
EN

Stack Overflow用户
提问于 2022-07-28 21:30:36
回答 1查看 45关注 0票数 0

我正在尝试使用Ansible来部署到AWS中的两个区域,我现在让它处理一个区域。问题是,我只想执行我的primary_regionsecondary_region,这取决于它使用的模板中的参数。

我的main.yaml

代码语言:javascript
复制
- 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

代码语言:javascript
复制
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条件下将引号放在字符串周围。好像什么都没用,我做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-29 07:33:39

你好像用了template_parameters道具。它应该是一个映射,但是您提供了一个字符串:

代码语言:javascript
复制
        template_parameters:
          PropName: "ansibleFile"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73159390

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档