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

nmstate should accept string representations of numerical values #26

Open
hthaller opened this issue Dec 20, 2021 · 0 comments
Open

nmstate should accept string representations of numerical values #26

hthaller opened this issue Dec 20, 2021 · 0 comments

Comments

@hthaller
Copy link

It is not possible to use jinja2 expressions for variables with the type integer. Jinja2 expressions are always strings and the type validation fails with an error message.

In the following playbook the value for the attribute "prefix-length" is a jinja2 expression.

- hosts: myservers     
  gather_facts: true      
  vars:                   
    # this jinja2 expressions does not work in nmstate_apply/prefix-length
    prefix: '{{ (ansible_default_ipv4.address+"/"+ansible_default_ipv4.netmask) | ipaddr("prefix") | int }}'
    # a hardcoded value works  
    # prefix: 23          
    nmstate_config:       
          routes:         
            config:       
            - destination: 0.0.0.0/0
              metric: 300      
              next-hop-address: 10.161.24.1
              next-hop-interface: bond0 
          interfaces:          
          - name: bond0        
            type: bond         
            state: up          
            ipv4:         
              enabled: true    
              address:         
              - ip: 10.10.24.101  
                prefix-length: "{{ prefix }}"                           
              auto-gateway: true
              #auto-route-table-id: 0
              auto-routes: true
              dhcp: false      
            ipv6:         
              enabled: false   
              address: []      
              autoconf: false  
              dhcp: false      
            link-aggregation:
              mode: active-backup  
              options:         
                miimon: 101    
              port:       
              - eno1np0        
              - ens1f1np1      
                         
  tasks:           
    - nmstate_apply:      
        state: '{{ nmstate_config }}'

The playbook produces this error message:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was:     '23'

fatal: [myserver.example.org]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"<stdin>\", line 102, in <module>\n  File \"<stdin>\", line 94, in _ansiballz_main\n  File \"<stdin>\", line 40, in invoke_module\n  File \"/usr/lib64/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib64/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_nmstate_apply_payload__jsq2n84/ansible_nmstate_apply_payload.zip/ansible/modules/nmstate_apply.py\", line 106, in <module>\n  File \"/tmp/ansible_nmstate_apply_payload__jsq2n84/ansible_nmstate_apply_payload.zip/ansible/modules/nmstate_apply.py\", line 102, in main\n  File \"/tmp/ansible_nmstate_apply_payload__jsq2n84/ansible_nmstate_apply_payload.zip/ansible/modules/nmstate_apply.py\", line 98, in run_module\n  File \"/tmp/ansible_nmstate_apply_payload__jsq2n84/ansible_nmstate_apply_payload.zip/ansible/modules/nmstate_apply.py\", line 75, in run\n  File \"/usr/lib/python3.6/site-packages/libnmstate/netapplier.py\", line 71, in apply\n    validator.schema_validate(desired_state)\n  File \"/usr/lib/python3.6/site-packages/libnmstate/validator.py\", line 41, in schema_validate\n    js.validate(data, validation_schema)\n  File \"/usr/lib/python3.6/site-packages/jsonschema/validators.py\", line 541, in validate\n    cls(schema, *args, **kwargs).validate(instance)\n  File \"/usr/lib/python3.6/site-packages/jsonschema/validators.py\", line 130, in validate\n    raise error\njsonschema.exceptions.ValidationError: '23' is not of type 'integer'\n\nFailed validating 'type' in schema['properties']['interfaces']['items']['allOf'][2]['allOf'][0]['properties']['ipv4']['properties']['address']['items']['properties']['prefix-length']:\n    {'type': 'integer'}\n\nOn instance['interfaces'][0]['ipv4']['address'][0]['prefix-length']:\n    '23'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

The expectation is that nmstate should accept string representations of numerical values too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant