saltstack-formulas / dhcpd-formula

http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
8 stars 56 forks source link

[BUG] allow and deny items parsed on single line #50

Closed Mandorath closed 3 years ago

Mandorath commented 4 years ago

Your setup

Formula commit hash / release tag

The formula used is v0.11.1, I checked the code in the master branch and it has the same problem.

Versions reports (master & minion)

Salt Version: Salt: 2019.2.4

Dependency Versions: cffi: Not Installed cherrypy: Not Installed dateutil: Not Installed docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed ioflo: Not Installed Jinja2: 2.8.1 libgit2: Not Installed libnacl: Not Installed M2Crypto: 0.33.0 Mako: Not Installed msgpack-pure: Not Installed msgpack-python: 0.5.6 mysql-python: Not Installed pycparser: Not Installed pycrypto: Not Installed pycryptodome: Not Installed pygit2: Not Installed Python: 3.6.8 (default, Aug 7 2019, 17:28:10) python-gnupg: Not Installed PyYAML: 3.11 PyZMQ: 15.3.0 RAET: Not Installed smmap: Not Installed timelib: Not Installed Tornado: 4.4.2 ZMQ: 4.1.4

System Versions: dist: centos 7.7.1908 Core locale: UTF-8 machine: x86_64 release: 3.10.0-1062.18.1.el7.x86_64 system: Linux version: CentOS Linux 7.7.1908 Core

Pillar / config used

Below an example of the pillar file used. Note the allow key.

dhcpd:
    domain_name: example.org
    authoritative: false
    omapi_port: port
    omapi_key: key
    next-server: ip-address
    ddns_update_style: none
    keys:                    # Replace values below with created key
      key:
          algorithm: algorithm
          secret: key
    allow:
      - booting
      - bootp
    domain_name_servers:
        - ns1.example.org       # replace and add the local dns server if exists
    default_lease_time: 43200
    max_lease_time: 86400
    log_facility: local7

Bug details

Describe the bug

When running the formula and adding items 'allow' items in the pillar file they are pasted after each other and after the last item declared before it. This is caused to due to the for loop stripping the new lines. The first option when not specified is dhcpd.use_host_decl_names, which when not specified pastes the allow items behind a commented item.

Output:

use-host-decl-names off;allow booting;allow bootp;

Steps to reproduce the bug

Do not specify the key dhcpd.use_host_decl_names and add several allow items like shown in the pillar example.

Expected behaviour

Output everything with newlines properly like show below.

use-host-decl-names off;

allow booting; allow bootp;

Attempts to fix the bug

Below the dhcp.allow with the allow in its own line

    {%- if dhcpd.allow %}
      {% if dhcpd.allow is iterable and dhcpd.allow  is not string %}  
        {%- for item in dhcpd.allow  %}  
allow {{ item }};  
       {%- endfor %}  
      {%- else %}
allow {{ dhcpd.allow }};  
      {%- endif %}  
    {%- endif %}  

Using the code above will result in the mentioned expected outcome

Additional context

Mandorath commented 4 years ago

Not sure why markdown code block is ignoring new lines, tried several methods...

myii commented 4 years ago

@Mandorath Have a look at the edit I made. You need to gate the code block with three backticks and you can add an optional code language for colour highlighting. So that was:

```jinja
    {%- if dhcpd.allow %}
      {% if dhcpd.allow is iterable and dhcpd.allow  is not string %}  
        {%- for item in dhcpd.allow  %}  
    allow {{ item }};  
       {%- endfor %}  
      {%- else %}allow {{ dhcpd.allow }};  
      {%- endif %}  
    {%- endif %} 
Mandorath commented 4 years ago

@myii Thanks! I'm still reading myself up on all of this :).

geertwitter commented 3 years ago

Hello, any progress on this item? It would be nice to have an update on this formula with the bug fixed.

myii commented 3 years ago

@Mandorath @geertwitter Fix proposed in #52. Feel free to test it out and comment there.

Tricked by @daks (in Slack) into working on this!!

geertwitter commented 3 years ago

Thanks for the fast response!

myii commented 3 years ago

@Mandorath @geertwitter Fix has been merged, let us know if there are any problems, either here or in #52.

saltstack-formulas-travis commented 3 years ago

:tada: This issue has been resolved in version 0.11.2 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: