Jinja模板中的盐粒

时间:2016-01-22 19:44:54

标签: jinja2 salt-stack

我想在SaltStack中做一些简单的事情:使用公式管理/etc/apt/sources.list文件。这是我的formula/init.sls文件中的相关部分:

/etc/apt/sources.list:
  - file.managed:
    - template: jinja
    - source: salt://pkg/files/etc/apt/sources.list
    - user: root
    - group: root
    - mode: 0644

refresh-apt:
  cmd.wait:
    - name: '/usr/bin/apt-get -y update'
    - watch:
      - file: /etc/apt/sources.list

这是文件pkg/files/etc/apt/sources.list

{{ pillar['headers']['salt']['file'] }}

deb http://{{ grains['aws_package_zone'] }}.ec2.archive.ubuntu.com/ubuntu/ {{ grains['oscodename'] }} main universe multiverse
deb-src http://{{ grains['aws_package_zone'] }}.ec2.archive.ubuntu.com/ubuntu/ {{ grains['oscodename'] }} main universe multiverse

deb http://{{ grains['aws_package_zone'] }}.ec2.archive.ubuntu.com/ubuntu/ {{ grains['oscodename'] }}-updates main universe multiverse
deb-src http://{{ grains['aws_package_zone'] }}.ec2.archive.ubuntu.com/ubuntu/ {{ grains['oscodename'] }}-updates main universe multiverse

deb http://{{ grains['aws_package_zone'] }}.ec2.archive.ubuntu.com/ubuntu/ {{ grains['oscodename'] }}-backports main universe multiverse
deb-src http://{{ grains['aws_package_zone'] }}.ec2.archive.ubuntu.com/ubuntu/ {{ grains['oscodename'] }}-backports main universe multiverse

deb http://security.ubuntu.com/ubuntu {{ grains['oscodename'] }}-security main universe multiverse
deb-src http://security.ubuntu.com/ubuntu {{ grains['oscodename'] }}-security main universe multiverse

grains['aws_package_zone']在这种情况下返回字符串us-west-2(或者您所在区域的任何代码),grains['oscodename']将返回该版本的Ubuntu代号名称:可靠的,xenial等。

显然,Salt不喜欢这样,因为当我尝试运行state.highstate时,我收到以下错误:

machine.fqdn:
    Data failed to compile:
----------
    ID /etc/apt/sources.list in SLS pkg is not a dictionary

不确定我做错了什么......有什么建议吗?对不起,如果这是基本的。

1 个答案:

答案 0 :(得分:1)

安德鲁在评论中提到,问题在于/etc/apt/sources.list定义中的额外“ - ”:

...
/etc/apt/sources.list:
  - file.managed: <<-- remove this dash; should be just 'file.managed'
    - template: jinja
...