【问题标题】:ansible - Incorrect type. Expected "object"ansible - 类型不正确。预期的“对象”
【发布时间】:2019-12-19 07:38:04
【问题描述】:

site.yaml

---
- name: someapp deployment playbook
  hosts: localhost
  connection: local
  gather_facts: no
  vars_files:
    - secrets.yml
  environment:
    AWS_DEFAULT_REGION: "{{ lookup('env', 'AWS_DEFAULT_VERSION') | default('ca-central-1', true) }}"
  tasks:
    - include: tasks/create_stack.yml
    - include: tasks/deploy_app.yml

create_stack.yml

---
- name: task to create/update stack
  cloudformation:
    stack_name: someapp
    state: present
    template: templates/stack.yml
    template_format: yaml
    template_parameters:
      VpcId: "{{ vpc_id }}"
      SubnetId: "{{ subnet_id }}"
      KeyPair: "{{ ec2_keypair }}"
      InstanceCount: "{{ instance_count | default(1) }}"
      DbSubnets: "{{ db_subnets | join(',') }}"
      DbAvailabilityZone: "{{ db_availability_zone }}"
      DbUsername: "{{ db_username }}"
      DbPassword: "{{ db_password }}"
    tags:
      Environment: test
  register: cf_stack

- name: task to output stack output
  debug: msg={{ cf_stack }}
  when: debug is defined

debug: msg={{ cf_stack }} 行出错:

This module prints statements during execution and can be useful for debugging variables or expressions without necessarily halting the playbook. Useful for debugging together with the 'when:' directive.

This module is also supported for Windows targets.

Incorrect type. Expected "object".

Ansible 文档允许上述语法,如图here

$ ansible --version
ansible 2.5.1
....

如何解决这个错误?

【问题讨论】:

标签: ansible


【解决方案1】:

您仍然需要记住以{ 开头的行的引号,即使使用速记符号:

- debug: msg="{{ cf_stack }}"

使用完整的 YAML 表示法会更明显:

- debug:
    msg: "{{ cf_stack }}"

另外,鉴于这是一个变量,你可以这样做:

-  debug:
     var: cf_stack

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-19
  • 2019-10-30
  • 2012-08-17
  • 2016-08-05
  • 2021-10-11
相关资源
最近更新 更多