{%- if pillar.puppet.masterless.enabled %}

include:
- git
- puppet.common

{%- for module in pillar.puppet.masterless.modules %}

{%- if module.source == 'git' %}
puppet_module_{{ module.name }}:
  git.latest:
  - name: {{ module.address }}
  - target: /etc/puppet/modules/{{ module.name }}
  - rev: {{ module.rev }}
  - require:
    - pkg: puppet_packages
    - pkg: git_packages
{%- endif %}

{%- if module.source == 'puppet' %}
puppet_module_{{ module.name }}:
  cmd.run:
  - name: puppet module install {{ module.address }}
  - unless: test -e /etc/puppet/modules/{{ module.name }}
  - require:
    - pkg: puppet_packages
    - pkg: git_packages
{%- endif %}


{%- endfor %}

{%- endif %}