无法通过 Ansible 将 Cloud Formation 部署为 Jinja 模板

我的角色main.yml如下所示


cat ansible/playbooks/roles/patching-cf-ssm/tasks/main.yml

---

- include_vars: "{{playbook_dir}}/vars/patching-config.yml"

  ignore_errors: yes


- name: Create a Cloudformation Stack Windows

  cloudformation:

    stack_name: "something pleasant-static"

    state: "present"

    region: "{{ AWS_REGION }}"

    disable_rollback: true

    template_body: "{{ lookup('template', '../../cloudformation/patching/PatchBaseline.yaml.j2') }}"

  #when: OStype == "WINDOWS"

  with_items: "{{ my_os_baseline }}"

最后,Jinja 模板如下:


[ansible@ip-172-31-40-59 awsManagedServiceInstance]$ cat cloudformation/patching/PatchBaseline.yaml.j2

---

Resources:

  WindowsBaseline:

    Type: AWS::SSM::PatchBaseline

    Properties:

      Name: My-Managed-{{item.OS}}-Baseline

      Description: {{item.OS}} Baseline for {{item.SEVERITY}} with Rating {{item.PatchFilters_Values}}

      OperatingSystem: {{ item.OS }}

      PatchGroups:

        - {{ item.PatchGroup | indent( width=7, indentfirst=True ) }}

        # - WinProdLastFri09PM01

        # - WinProdLastSat09PM01

        # - WinNonProdDayOne09PM01

        # - WinNonProdDayTwo09PM01

      ApprovalRules:

        PatchRules:

          - PatchFilterGroup:

              PatchFilters:

                - Values:

                  {{ item.PatchFilters_Values | indent( width=14, indentfirst=True ) }}

                  Key: {{ item.SEVERITY }}

                - Values:

                  {{ item.CLASSIFICATION_Values | indent( width=14, indentfirst=True ) }}

                  Key: CLASSIFICATION

                - Values:

                    - APPLICATION

                  Key: PATCH_SET

            ApproveAfterDays: 7

            ComplianceLevel: CRITICAL

不幸的是,我收到如下错误:


fatal: [localhost]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'template'. Error was a <type 'exceptions.AttributeError'>, original message: 'list' object has no attribute 'splitlines'"}

不知道它首先意味着什么以及如何解决它。


慕村225694
浏览 116回答 1
1回答

动漫人物

&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;{{&nbsp;item.PatchGroup&nbsp;|&nbsp;indent(&nbsp;width=7,&nbsp;indentfirst=True&nbsp;)&nbsp;}}您正在将 a 发送list到需要换行符分隔字符串的函数中您可以轻松重现该爆炸:-&nbsp;debug: &nbsp;&nbsp;&nbsp;&nbsp;msg:&nbsp;'{{&nbsp;["alpha",&nbsp;"beta"]&nbsp;|&nbsp;indent(&nbsp;width=7,&nbsp;indentfirst=True&nbsp;)&nbsp;}}'然后同样微不足道的解决方法join是list-&nbsp;debug: &nbsp;&nbsp;&nbsp;&nbsp;msg:&nbsp;'{{&nbsp;["alpha",&nbsp;"beta"]&nbsp;|&nbsp;join("\n")&nbsp;|&nbsp;indent(&nbsp;width=7,&nbsp;indentfirst=True&nbsp;)&nbsp;}}'
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python