ansible-类型错误。预期的“对象”

时间:2019-12-18 23:08:26

标签: ansible

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
....

如何解决此错误?

1 个答案:

答案 0 :(得分:1)

即使使用简写形式,您仍需要记住以{开头的行的引号:

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

使用完整的YAML标记会更明显:

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

此外,鉴于这是一个变量,您可以这样做:

-  debug:
     var: cf_stack