Developer

 View Only
  • 1.  ansible arubaoss network_cli - jinja2 issues

    Posted Apr 27, 2020 01:27 PM

    I have some plabyooks that are working, but when im trying to start using jinja2 i'm getting some failures. Attached are my files.

     

    tree
    .
    ├── host_vars
    │   └── s-2930f-2.yml
    ├── inventory.yml
    ├── playbook.yml
    └── templates
         └── vlan.j2

     

     

    PLAY [all] ***********************************************************************************************************************************************************************************

    TASK [Global config: Create VLAN] ************************************************************************************************************************************************************
    [WARNING]: Platform linux on host s-2930f-2 is using the discovered Python interpreter at /usr/bin/python3.6, but future installation of another Python interpreter could change this. See
    https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
    fatal: [s-2930f-2]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3.6"}, "changed": false, "command": "{% for vlan in vlans %}", "msg": "[24;56H %}Invalid input: {%\r
    Aruba-2930F-8G-PoEP-2SFPP(config)# ", "rc": -32603}

    PLAY RECAP ***********************************************************************************************************************************************************************************
    s-2930f-2 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

    [root@ansible1 vlanVarsv02]# ansible-playbook playbook.yml -i inventory.yml -vvv
    ansible-playbook 2.9.7
    config file = /root/ansible/vlanVarsv02/ansible.cfg
    configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    ansible python module location = /root/.local/lib/python3.6/site-packages/ansible
    executable location = /usr/bin/ansible-playbook
    python version = 3.6.8 (default, Nov 10 2019, 15:33:49) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4.0.1)]
    Using /root/ansible/vlanVarsv02/ansible.cfg as config file
    host_list declined parsing /root/ansible/vlanVarsv02/inventory.yml as it did not pass its verify_file() method
    script declined parsing /root/ansible/vlanVarsv02/inventory.yml as it did not pass its verify_file() method
    Parsed /root/ansible/vlanVarsv02/inventory.yml inventory source with yaml plugin

    PLAYBOOK: playbook.yml ***********************************************************************************************************************************************************************
    1 plays in playbook.yml

    PLAY [all] ***********************************************************************************************************************************************************************************
    META: ran handlers

    TASK [Global config: Create VLAN] ************************************************************************************************************************************************************
    task path: /root/ansible/vlanVarsv02/playbook.yml:4
    <172.19.43.7> ESTABLISH LOCAL CONNECTION FOR USER: root
    <172.19.43.7> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-5362cko_5me1 `"&& mkdir /root/.ansible/tmp/ansible-local-5362cko_5me1/ansible-tmp-1588007743.3714168-5369-88970546045761 && echo ansible-tmp-1588007743.3714168-5369-88970546045761="` echo /root/.ansible/tmp/ansible-local-5362cko_5me1/ansible-tmp-1588007743.3714168-5369-88970546045761 `" ) && sleep 0'
    <s-2930f-2> Attempting python interpreter discovery
    <172.19.43.7> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND && sleep 0'
    <172.19.43.7> EXEC /bin/sh -c '/usr/bin/python3.6 && sleep 0'
    <s-2930f-2> Python interpreter discovery fallback (unsupported Linux distribution: oracle)
    Using module file /root/.local/lib/python3.6/site-packages/ansible/modules/network/arubaoss/arubaoss_config.py
    <172.19.43.7> PUT /root/.ansible/tmp/ansible-local-5362cko_5me1/tmpj5nqx9pu TO /root/.ansible/tmp/ansible-local-5362cko_5me1/ansible-tmp-1588007743.3714168-5369-88970546045761/AnsiballZ_arubaoss_config.py
    <172.19.43.7> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-5362cko_5me1/ansible-tmp-1588007743.3714168-5369-88970546045761/ /root/.ansible/tmp/ansible-local-5362cko_5me1/ansible-tmp-1588007743.3714168-5369-88970546045761/AnsiballZ_arubaoss_config.py && sleep 0'
    <172.19.43.7> EXEC /bin/sh -c '/usr/bin/python3.6 /root/.ansible/tmp/ansible-local-5362cko_5me1/ansible-tmp-1588007743.3714168-5369-88970546045761/AnsiballZ_arubaoss_config.py && sleep 0'
    <172.19.43.7> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-5362cko_5me1/ansible-tmp-1588007743.3714168-5369-88970546045761/ > /dev/null 2>&1 && sleep 0'
    [WARNING]: Platform linux on host s-2930f-2 is using the discovered Python interpreter at /usr/bin/python3.6, but future installation of another Python interpreter could change this. See
    https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
    fatal: [s-2930f-2]: FAILED! => {
    "ansible_facts": {
    "discovered_interpreter_python": "/usr/bin/python3.6"
    },
    "changed": false,
    "command": "{% for vlan in vlans %}",
    "invocation": {
    "module_args": {
    "after": null,
    "api_version": "None",
    "backup": false,
    "backup_options": null,
    "before": null,
    "diff_against": null,
    "diff_ignore_lines": null,
    "host": null,
    "intended_config": null,
    "lines": null,
    "match": "line",
    "parents": null,
    "password": null,
    "port": null,
    "provider": null,
    "replace": "line",
    "running_config": null,
    "save_when": "never",
    "src": "templates/vlan.j2",
    "ssh_keyfile": null,
    "timeout": null,
    "use_ssl": null,
    "username": null,
    "validate_certs": false
    }
    },
    "msg": "[24;56H %}Invalid input: {%\r
    Aruba-2930F-8G-PoEP-2SFPP(config)# ",
    "rc": -32603
    }

    PLAY RECAP ***********************************************************************************************************************************************************************************
    s-2930f-2 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

     

     

    error output is here:

     

     

     

    Attachment(s)

    txt
    s-2930f-2.txt   172 B 1 version
    txt
    inventory.yml.txt   226 B 1 version
    txt
    playbook.yml.txt   136 B 1 version
    txt
    vlan.j2.txt   112 B 1 version


  • 2.  RE: ansible arubaoss network_cli - jinja2 issues

    Posted Apr 27, 2020 02:04 PM

    fixed  the closing of the loop in the j2 file, but still same errors



  • 3.  RE: ansible arubaoss network_cli - jinja2 issues

    Posted Apr 27, 2020 03:53 PM

    Hey Luke,

     

    Thanks for reaching out! I'm taking a look at your issue right now. I noticed though that in your original post that there's nothing after "error output is here:" -- perhaps you forgot to copy that in?

     

    Thanks,

    Derek

     

    Edit: It looks actually like you did post the error output, just above the "error output is here:" message. If that's right, I'll get started seeing if I can reproduce that issue.



  • 4.  RE: ansible arubaoss network_cli - jinja2 issues

    Posted Apr 27, 2020 05:19 PM

    yeah that's the case, sorry.

     

    I am thinking I'm not using the jinja/template stuff correctly, I'm going off another example from a Pluralsight course.. I think I'm getting closer using a bit of a different structure, but still ultimately not getting what I'm looking for.

     

    I have a template working, and it's outputing the syntax to a text file, but ultimatley instead of going to a text file I want this sent to the SSH CLI of the switch.

     

    hope that makes sense.



  • 5.  RE: ansible arubaoss network_cli - jinja2 issues

    Posted Apr 27, 2020 06:13 PM

    so it appears that arubaoss_config doesn't put src through jinja; but im finding that the (ansible built in module) aruba_config module does... 

     

    I believe the built in ansible modules can put src through jinja, like that's a standard for them, is there a reason arubaoss_config doesn't do that?



  • 6.  RE: ansible arubaoss network_cli - jinja2 issues
    Best Answer

    Posted Apr 27, 2020 06:18 PM
      |   view attached

    Hey Luke,

     

    Ah, thanks for the clarification. The issue in the playbook that you linked in your original post is that the "arubaoss_config" module doesn't perform any template rendering. There's an inbuilt Ansible module that exists for that purpose, the "template" module. Since you have the template rendering working now, and it's outputting the syntax to a text file, you've probably figured this part out.

     

    The part you're missing now is getting the contents of the text file onto the CLI of the switch. That's where the "arubaoss_config" module fits into the picture. You can use this module to read the contents of that file and copy those contents onto the config of the switch.

     

    So after your task where you render the template into a file containing the VLAN lines, you'll need to create another task using the arubaoss_config module and specify the "src" parameter to tell the module to read the config lines from the output file in the previous step.

     

    Check out the playbook file I've attached. I ran it and it worked. Note that I added an extra variable for the output file containing the VLAN config lines. That variable value is a filepath that is relative to the current working directory in which you execute the ansible-playbook command.

     

    I didn't have to modify any of the other three files that I downloaded from your attachment. Let me know if you have further questions!

     

    Thanks,

    Derek

     

    Attachment(s)

    txt
    playbook.yml.txt   338 B 1 version


  • 7.  RE: ansible arubaoss network_cli - jinja2 issues

    Posted May 07, 2020 01:23 PM

    thanks!