Package: cfgtemplater
cfgtemplatercfgtemplater is a Jinja2 template CLI rendering tool. It allows to integrate metadata and defaults variables values within a YAML header. It is also integrates basic IP filters and tests since it's main development purpose is to generate network devices configuration files. It is as well able to load external filters and tests from other python modules.Installationpip install cfgtemplaterUsageusage: cfgtemplater [-h] [-y YAML] [-p KEY=VALUE] [-e FILE] TEMPLATE

A simple YAML/Jinja2 config generator.

positional arguments:
  TEMPLATE      template

optional arguments:
  -h, --help    show this help message and exit
  -y YAML       YAML file
  -p KEY=VALUE  key/value pair
  -e FILE       Jinja2 extensions modulesUsage examplesLoad variables from a YAML filecfgtemplater -y variables.yml template.j2Load variables from multiple YAML files (merged in order)cfgtemplater -y default_variables.yml -y instance_variables.yml template.j2Override variables from CLIcfgtemplater -y default_variables -p 'variable1=value1' template.j2Pass python literals from CLIcfgtemplater -p "variable1=[{'name':'varx', 'value':'x'}, {'name':'vary', 'value':'y'}]" template.j2Template(Main) template may look like this:---name: Example templatevariables:variable1:default:      "example"description:  "example variable"variable2:default:- value: 0name: zero- value: 1name: one---This is an{{variable1}}file.{%forvariableinvariable2%}This is a{{variable.name}}:{{variable.value}}{%endfor%}{{variable3}}The YAML header may contain template metadata (like name, description, whatever). It may as well contain default variables or variables descriptions or any variable metadata. Defaults values are injected in the template when rendering, and can be redefined using CLI or YAML file.ExtensionsJinja2 filters and tests can be loaded from external files.Load ansible ipaddr filter (ansible_ipaddr.py)importnetaddrfromansible.plugins.filter.ipaddrimport*Render template using ipaddr filterscfgtemplater -e ansible_ipaddr.py template.j2Basic module usage>>>fromcfgtemplater.config_templateimportConfigTemplate>>>t=ConfigTemplate('examples/example1.j2')>>>t.name'Example template'>>>t.variables{'variable1':{'default':'example','description':'example variable'},'variable2':{'default':[{'value':0,'name':'zero'},{'value':1,'name':'one'}]}}>>>t.content'This is an {{ variable1 }} file.\n\n{% for variable in variable2 %}\nThis is a {{ variable.name }} : {{ variable.value }}\n{% endfor %}\n\n{{ variable3 }}\n'>>>print(t.render({'variable3':'TEST'}))Thisisanexamplefile.Thisisazero:0Thisisaone:1TESTIntegrated filters and testsIP filtersfirst_address{{ipv4_net|first_address}}{{ipv6_net|first_address}}192.0.2.1/24
2001:db8::1/120last_address{{ipv4_net|last_address}}{{ipv6_net|last_address}}192.0.2.254/24
2001:db8::ff/120address{{ipv4_net|address}}{{ipv6_net|address}}192.0.2.0
2001:db8::network{{ipv4_net|first_address|network}}{{ipv6_net|first_address|network}}192.0.2.0/24
2001:db8::/120broadcast{{ipv4_net|broadcast}}{{ipv6_net|broadcast}}192.0.2.255/24
2001:db8::ff/120prefixlen{{ipv4_net|prefixlen}}{{ipv6_net|prefixlen}}24
120netmask{{ipv4_net|netmask}}{{ipv6_net|netmask}}255.255.255.0
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00hostmask{{ipv4_net|first_address|hostmask}}{{ipv6_net|first_address|hostmask}}0.0.0.255
::ffcompress{{'192.000.002.001'|compress}}{{'2001:0db8:0000:0000:0000:0000:0000:0001'|compress}}192.0.2.1
2001:db8::1uncompress{{'192.0.2.1'|uncompress}}{{'2001:db8::1'|uncompress}}192.000.002.001
2001:0db8:0000:0000:0000:0000:0000:0001octets{%foroctetinipv4_net|octets%}{{octet}}{%endfor%}192
  0
  2
  0hextets{%forhextetinipv6_net|hextets%}{{hextet}}{%endfor%}2001
  0db8
  0000
  0000
  0000
  0000
  0000
  0000IP testsis_ip{{ipv4_net|is_ip}}{{ipv6_net|is_ip}}{{'test'|is_ipTrue
True
Falseis_ipv4{{ipv4_net|is_ipv4}}{{ipv6_net|is_ipv4}}True
Falseis_ipv6{{ipv6_net|is_ipv6}}{{ipv4_net|is_ipv6}}True
Falseis_ip_net{{ipv4_net|is_ip_net}}{{ipv6_net|is_ip_net}}{{ipv6_net|first_address|is_ip_net}}{{ipv6_net|first_address|is_ip_net}}True
True
False
Falseis_ipv4_net{{ipv4_net|is_ipv4_net}}{{ipv6_net|is_ipv4_net}}{{ipv4_net|first_address|is_ipv4_net}}{{ipv6_net|first_address|is_ipv4_net}}True
False
False
Falseis_ipv6_net{{ipv6_net|is_ipv6_net}}{{ipv4_net|is_ipv6_net}}{{ipv6_net|first_address|is_ipv4_net}}{{ipv4_net|first_address|is_ipv4_net}}True
False
False
Falseis_ipv4_host{{ipv4_net|first_address|is_ipv4_host}}{{ipv4_net|is_ipv4_host}}True
False