# Unable to insert sshkey with nxos\_command in Ansible 2.1

**URL:** <https://forum.ansible.com/t/unable-to-insert-sshkey-with-nxos-command-in-ansible-2-1/22579>\
**Category:** Ansible Project\
**Created:** [September 17, 2016, 5:10pm UTC](https://forum.ansible.com/t/unable-to-insert-sshkey-with-nxos-command-in-ansible-2-1/22579 "2016-09-17T17:10:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Carter](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@Steven\_Carter](https://forum.ansible.com/u/Steven_Carter)\
**Post date:** [September 17, 2016, 5:10pm UTC](https://forum.ansible.com/t/unable-to-insert-sshkey-with-nxos-command-in-ansible-2-1/22579/1 "2016-09-17T17:10:00Z")

</div>

I have the following two plays to create users with ssh keys in NXOS:

- name: Create User  
nxos\_config:  
lines:

- username “{{ item }}” role network-admin  
provider: “{{ cli }}”  
with\_items: “{{ cil\_network\_admins }}”

- name: Create User’s SSH Keys  
nxos\_config:  
lines:

- username “{{ item }}” sshkey “{{ user\_data[item].ssh\_key }}”  
provider: “{{ cli }}”  
with\_items: “{{ cil\_network\_admins }}”

The data structures are:

user\_data:  
stevenca:  
name: “Steven Carter”  
uid: 2000  
group: admin  
ssh\_key: “ssh-rsa Rest of SSH Key…”

cil\_network\_admins:

- stevenca

I do not get any errors:

TASK [Create User] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [XXX.XXX.XXX.129] =\> (item=stevenca)  
changed: [XXX.XXX.XXX.128] =\> (item=stevenca)

TASK [Create User’s SSH Keys] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [XXX.XXX.XXX.129] =\> (item=stevenca)  
changed: [XXX.XXX.XXX.128] =\> (item=stevenca)

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
XXX.XXX.XXX.128 : ok=4 changed=2 unreachable=0 failed=0  
XXX.XXX.XXX.129 : ok=4 changed=2 unreachable=0 failed=0

But it does not work. I get ‘username stevenca role network-admin’ in the switch’s config, but no ssh key. Is there a length limit that silently eats the SSH key?

The above is using ‘cli’ for transport. When I use ‘nxapi’, I get:

TASK [Create User] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [XXX.XXX.XXX.128] =\> (item=stevenca)  
failed: [XXX.XXX.XXX.129] (item=stevenca) =\> {“clierror”: “% String failed to match token pattern\n”, “code”: “400”, “failed”: true, “item”: “stevenca”, “msg”: “CLI execution error”}

TASK [Create User’s SSH Keys] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [XXX.XXX.XXX.128] (item=stevenca) =\> {“clierror”: “invalid SSH key format\n”, “code”: “400”, “failed”: true, “item”: “stevenca”, “msg”: “CLI execution error”}

I verified the key by adding manually, and it worked fine. It seems like the above could come from truncation as well.

Thanks,

Steven.

---

<div class="post-metadata">

**Author:** ![psprygada](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@psprygada](https://forum.ansible.com/u/psprygada)\
**Post date:** [September 19, 2016, 3:19am UTC](https://forum.ansible.com/t/unable-to-insert-sshkey-with-nxos-command-in-ansible-2-1/22579/2 "2016-09-19T03:19:47Z")

</div>

Strange, I just tested with the the stable-2.1 branch and I am not seeing these issues. Both Cli and Nxapi transports are working just fine.

Could you provide the output of both “ansible --version” as well as “show version” from your device?

---

<div class="post-metadata">

**Author:** ![Steven\_Carter](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@Steven\_Carter](https://forum.ansible.com/u/Steven_Carter)\
**Post date:** [September 20, 2016, 1:46am UTC](https://forum.ansible.com/t/unable-to-insert-sshkey-with-nxos-command-in-ansible-2-1/22579/3 "2016-09-20T01:46:05Z")

</div>

I goofed and qouted the variable. This did not work:

- name: Create User’s SSH Keys  
nxos\_config:  
lines:
- username “{{ item }}” sshkey “{{ user\_data[item].ssh\_key }}”  
provider: “{{ cli }}”  
with\_items: “{{ network\_admins }}”

This did:

- name: Create User’s SSH Keys  
nxos\_config:  
lines:
- username {{ item }} sshkey {{ user\_data[item].ssh\_key }}  
provider: “{{ cli }}”  
with\_items: “{{ network\_admins }}”

Have you had any luck with injecting ssh keys into ios?

Thanks,

Steven.
