Snippets

iSeatz jinja issue

Updated by Tim Kelley

File ssnip.md Modified

  • Ignore whitespace
  • Hide word diff
     - wait_for_sync: false
 
 ```
+#### contents of global/settings.sls
 
 ```
+{% set pval = salt['pillar.get'] %}
+{% set gval = salt['grains.get'] %}
+
+# determine if we are in ec2 or not
+{% set is_aws = salt['grains.get']('ec2:services:partition') %}
+{% if is_aws is equalto 'aws' %}
+  {% set ec2_instance = 'true' %}
+{% endif %}
+
+{% if ec2_instance is defined %}
+  {% set private_ip = salt['grains.get']('ec2:private_ip') %}
+{% else %}
+  {% set private_ip = salt['grains.get']('ipv4')|last %}
+{% endif %}
+
+{% set fqdn = salt['grains.get']('fqdn') %}
+{% set domain = salt['grains.get']('domain') %}
+{% set short_host_name = salt['grains.get']('host') %}
+
+{% if ec2_instance is defined %}
+  {% set Name = salt['grains.get']('ec2_tags:Name') %}
+  {% set eip = salt['grains.get']('ec2_tags:eip') %}
+  {% set roles = salt['grains.get']('ec2_tags:roles') %}
+  {% set services = salt['grains.get']('ec2_tags:services') %}
+  {% set saltenv = salt['grains.get']('ec2_tags:saltenv') %}
+  {% set cost_allocation = salt['grains.get']('ec2_tags:cost_allocation') %}
+  {% set instance_type = salt['grains.get']('ec2:instance_type') %}
+  {% set region = salt['grains.get']('ec2:region') %}
+  {% set instance_id = salt['grains.get']('ec2:instance_id') %}
+  {% set ami_launch_index = salt['grains.get']('ec2:ami_launch_index') %}
+  {% set availability_zone = salt['grains.get']('ec2:availability_zone') %}
+  {% set iam_role = salt['grains.get']('ec2:iam:info:instance_profile_arn') %}
+  {% if 'root-image' not in roles %}
+    {% set ptr_value = salt['cmd.shell']('/usr/local/sbin/my-ptr') %}
+  {% endif %}
+{% endif %}
+```
+
+
+the error
+```
 [ERROR   ] Rendering exception occurred: Jinja variable 'jinja2.environment.TemplateModule object' has no attribute 'ptr_value'
 [ERROR   ] An un-handled exception was caught by salt's global exception handler:
 SaltRenderError: Jinja variable 'jinja2.environment.TemplateModule object' has no attribute 'ptr_value'
Updated by Tim Kelley

File ssnip.md Modified

  • Ignore whitespace
  • Hide word diff
+the sls:
+```
+{% import 'global/settings.sls' as global with context %}
+
+ec2.set_private_A_record:
+  boto_route53.present:
+    - zone: iz.
+    - name: {{ global.fqdn }}.
+    - value: {{ global.private_ip }}
+    - record_type: A
+    - ttl: 60
+    - wait_for_sync: False
+
+ec2.set_private_PTR_record:
+  boto_route53.present:
+    - zone: 10.in-addr.arpa.
+    - name: {{ global.ptr_value }}
+    - value: {{ global.fqdn }}
+    - record_type: ptr
+    - wait_for_sync: false
+
+```
+
 ```
 [ERROR   ] Rendering exception occurred: Jinja variable 'jinja2.environment.TemplateModule object' has no attribute 'ptr_value'
 [ERROR   ] An un-handled exception was caught by salt's global exception handler:
Created by Tim Kelley

File ssnip.md Added

  • Ignore whitespace
  • Hide word diff
+```
+[ERROR   ] Rendering exception occurred: Jinja variable 'jinja2.environment.TemplateModule object' has no attribute 'ptr_value'
+[ERROR   ] An un-handled exception was caught by salt's global exception handler:
+SaltRenderError: Jinja variable 'jinja2.environment.TemplateModule object' has no attribute 'ptr_value'
+Traceback (most recent call last):
+  File "/usr/bin/salt-call", line 11, in <module>
+    salt_call()
+  File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 379, in salt_call
+    client.run()
+  File "/usr/lib/python2.7/dist-packages/salt/cli/call.py", line 58, in run
+    caller.run()
+  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 134, in run
+    ret = self.call()
+  File "/usr/lib/python2.7/dist-packages/salt/cli/caller.py", line 197, in call
+    ret['return'] = func(*args, **kwargs)
+  File "/usr/lib/python2.7/dist-packages/salt/modules/cp.py", line 261, in get_template
+    **kwargs)
+  File "/usr/lib/python2.7/dist-packages/salt/fileclient.py", line 676, in get_template
+    **kwargs
+  File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 178, in render_tmpl
+    output = render_str(tmplstr, context, tmplpath)
+  File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 386, in render_jinja_tmpl
+    buf=tmplstr)
+SaltRenderError: Jinja variable 'jinja2.environment.TemplateModule object' has no attribute 'ptr_value'
+```
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.