I am using ansible-napalm and trying to write a simple playbook to pull facts from network devices. I want to encrypt the passwords with ansible-vault, however regardless of what I try I keep getting the error: Vault format unhexlify error: Odd-length string
I initially was trying this in bash under the Windows subsystem for Linux and I thought this may be the issue so I recreated everything on a centos VM and still run into the same issue.
I have tried using encrypt-string to embed the encrypted pw directly into the playbook. I have also tried encrypting the file and calling the variable. Both methods give the same error.
I found this issue: Ansible-vault errors with "Odd-length string" And I thought the issue was to do with CRLF line terminators so I sorted that and made sure all files were ASCII text but this still gives the same errors.
My code is below, any help would be majorly appreciated because I am pulling my hair out!
---
- name: napalm_facts
hosts: all
connection: local
gather_facts: no
tasks:
- name: get facts from device
napalm_get_facts:
hostname: "{{ ansible_host }}"
username: 'admin'
password: "{{ napalm_password }}"
dev_os: 'ios'
register: result
- name: print results
debug: msg="{{ result }}"
I've tried the below methods, for reference.
ansible-vault encrypt vars/vaultpw.yml
ansible-vault encrypt_string password123 --ask-vault-pass