Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import YAML with context #288

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docker/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# vim: ft=jinja

{%- set tplroot = tpldir.split('/')[0] %}
{%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %}
{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap %}
{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %}
{%- import_yaml tplroot ~ "/osmap.yaml" as osmap %}
{%- import_yaml tplroot ~ "/codenamemap.yaml" as codenamemap %}
{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %}
{%- import_yaml tplroot ~ "/cpuarchmap.yaml" as cpuarchmap %}
{%- import_yaml tplroot ~ "/defaults.yaml" as default_settings with context %}
{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap with context %}
{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap with context %}
{%- import_yaml tplroot ~ "/osmap.yaml" as osmap with context %}
{%- import_yaml tplroot ~ "/codenamemap.yaml" as codenamemap with context %}
{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap with context %}
{%- import_yaml tplroot ~ "/cpuarchmap.yaml" as cpuarchmap with context %}
Comment on lines +5 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lucianovici Grepping through the .yaml files, these are the only ones that are using any Jinja for accessing data structures:

docker/osfamilymap.yaml:{%- if grains.os == 'MacOS' %}
docker/osfamilymap.yaml:    {%- set rootuser = salt['cmd.run']("stat -f '%Su' /dev/console") %}
docker/osfamilymap.yaml:    {%- set rootgroup = salt['cmd.run']("stat -f '%Sg' /dev/console") %}
docker/osfamilymap.yaml:{%- elif grains.os == 'Windows' %}
docker/osfamilymap.yaml:    {%- set rootuser = salt['cmd.run']("id -un") %}
docker/osfamilymap.yaml:{%- endif %}
docker/osfamilymap.yaml:                {%- if 'oscodename' in grains %}
docker/osfamilymap.yaml:        name: deb [arch=amd64] https://download.docker.com/linux/{{ grains.os|lower }} {{ grains.oscodename }} stable
docker/osfamilymap.yaml:                {%- endif %}
docker/osfamilymap.yaml:        key_url: "https://download.docker.com/linux/{{ grains.os|lower }}/gpg"
docker/osfamilymap.yaml:        baseurl: 'https://download.docker.com/linux/{{ grains.os|lower }}/$releasever/$basearch/stable'
docker/osfamilymap.yaml:        gpgkey: 'https://download.docker.com/linux/{{ grains.os|lower }}/gpg'
docker/osfamilymap.yaml:    rootuser: {{ rootuser | d('') }}
docker/osfamilymap.yaml:    rootuser: {{ rootuser | d('') }}
docker/codenamemap.yaml:      - linux-image-extra-{{ grains.kernelrelease }}
docker/osmap.yaml:        baseurl: 'https://download.docker.com/linux/centos/{{ grains.get('osmajorrelease', '') }}/$basearch/stable'

Thus, we only need to add with context to those particular imports (as was mentioned in the postgres-formula PR):

Suggested change
{%- import_yaml tplroot ~ "/defaults.yaml" as default_settings with context %}
{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap with context %}
{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap with context %}
{%- import_yaml tplroot ~ "/osmap.yaml" as osmap with context %}
{%- import_yaml tplroot ~ "/codenamemap.yaml" as codenamemap with context %}
{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap with context %}
{%- import_yaml tplroot ~ "/cpuarchmap.yaml" as cpuarchmap with context %}
{%- import_yaml tplroot ~ "/defaults.yaml" as default_settings %}
{%- import_yaml tplroot ~ "/osfamilymap.yaml" as osfamilymap with context %}
{%- import_yaml tplroot ~ "/osfingermap.yaml" as osfingermap %}
{%- import_yaml tplroot ~ "/osmap.yaml" as osmap with context %}
{%- import_yaml tplroot ~ "/codenamemap.yaml" as codenamemap with context %}
{%- import_yaml tplroot ~ "/osarchmap.yaml" as osarchmap %}
{%- import_yaml tplroot ~ "/cpuarchmap.yaml" as cpuarchmap %}

In fact, this is actually a reminder that we really want to move to our new v5 map.jinja, which emphasizes moving Jinja out of our YAML files.

Also, #290 has been merged, so if you rebase this PR on top, all the tests should pass.


{%- set _config = salt['config.get'](tplroot, default={}) %}
{%- set defaults = salt['grains.filter_by'](
Expand Down