1

I am trying to do something simple in SaltStack: manage the /etc/apt/sources.list file using a formula. Here's the relevant section in my formula/init.sls file:

/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

And here's the file 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

The grains['aws_package_zone'] returns the string us-west-2 in this case (or whatever code for the zone you're in) and grains['oscodename'] will return the name of the Ubuntu codename for that release: trusty, xenial, etc.

Clearly Salt doesn't like this because when I try to run state.highstate I get the following error:

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

Not sure what I'm doing wrong...any suggestions? Sorry if this is basic.

2
  • This question is a duplicate of this one; you can find your answer there. Also, rather than templating sources.list, you may want to look into the pkgrepo.managed state.
    – Andrew
    Commented Jan 23, 2016 at 15:25
  • (note that the actual problem is nothing to do with the grains access in jinja; that looks correct to me)
    – Andrew
    Commented Jan 23, 2016 at 15:35

1 Answer 1

3

As Andrew mentioned in his comment, the problem is with the extra '-' in the /etc/apt/sources.list definition:

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.