
{% if grains.os_family == 'Debian' %}

puppet_repo:
  pkgrepo.managed:
  - human_name: PuppetLabs
  - names:
    - deb http://apt.puppetlabs.com {{ grains.oscodename }} main
    - deb-src http://apt.puppetlabs.com {{ grains.oscodename }} main
    - deb http://apt.puppetlabs.com {{ grains.oscodename }} dependencies
    - deb-src http://apt.puppetlabs.com {{ grains.oscodename }} dependencies
  - file: /etc/apt/sources.list.d/puppetlabs.list
  - key_url: salt://puppet/conf/puppet-apt.gpg

{% if pillar.puppet.master is defined %}
{% set puppet_packages = ['puppetmaster'] %}
{% endif %}

{% if pillar.puppet.agent is defined or pillar.puppet.masterless is defined %}
{% set puppet_packages = ['puppet'] %}
{% endif %}

puppet_packages:
  pkg.installed:
  - names: {{ puppet_packages }}
  - require:
    - pkgrepo: puppet_repo

{% elif grains.os_family == 'RedHat' %}

puppet_repo:
  pkgrepo.managed:
  - human_name: PuppetLabs
  - name: deb https://yum.puppetlabs.com/dists/ {{ grains.oscodename }} main
  - file: /etc/yum.repos.d/puppetlabs.repo
  - key_url: salt://puppet/conf/puppet-yum.gpg

{% endif %}

/etc/puppet/puppet.conf:
  file.managed:
  - source: salt://puppet/conf/puppet.conf
  - template: jinja
  - mode: 755
  - require:
    - pkg: puppet_packages
