Reputation: 1663
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.
Upvotes: 1
Views: 4067
Reputation: 1663
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
...
Upvotes: 3