Unable to use "os_keypair" module, while "nova keypair-add" works

99 views
Skip to first unread message

Thiago Martins

unread,
Feb 29, 2016, 11:05:21 AM2/29/16
to Ansible Project
Hey guys!

 Ansible is AWESOME!    :-D

 I'm planning to move away from running "shell:" via Ansible, in favor of native modules, but, it is not working, as follows...

 Can someone explain to me, why this task works:

---
- name: ubuntu | uploading SSH Keypair into OpenStack
  environment: "{{ demo_openrc_env }}"
  shell: nova keypair-add --pub-key "/home/{{ubuntu_user}}/.ssh/id_rsa.pub" default
---

 And why this does NOT work:

---
- name: ubuntu | uploading SSH Keypair into OpenStack
  environment: "{{ demo_openrc_env }}"
  os_keypair:
      state: present
      name: default
      public_key_file: "/home/{{ubuntu_user}}/.ssh/id_rsa.pub"
---

---
ERROR:
-
TASK [os_user_key : ubuntu | uploading SSH Keypair into OpenStack] *************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'OpenStackCloud' object has no attribute 'get_keypair'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "parsed": false}
---

 What am I missing? Appending "-vvv" doesn't help either...

 I also tried to use the "clouds:" entry of "os_keypair" but, also, doesn't work... It doesn't find "mycloud", even if clouds.yml is there on same dir of task... So, I'll prefer for now, to use "environment:", if possible...

 Any clues?

 Thanks in advance!

Best,
Thiago

David Shrewsbury

unread,
Feb 29, 2016, 12:26:30 PM2/29/16
to Ansible Project
Hi!

You first need to upgrade your version of shade. The latest version is 1.4.0.

Second, you should not expect a clouds.yaml to be read from the current
directory because of the way Ansible works (copying modules to temp directories
on the target host before running them). Instead, place it either in the
/etc/openstack directory, or in ~/.config/openstack (of the user running the
task).

Alternatively, you can just use the normal OS_ environment variables, but you
should not mix use of env vars with clouds.yaml.

-David

Thiago Martins

unread,
Mar 10, 2016, 5:05:42 PM3/10/16
to Ansible Project
Thank you!

That explains why it wasn't working, I was using Python Shade 0.6.

I just filled a bug report on Launchpad to upgrade it to the latest stable Shade release.


Upgrade to latest stable version 1.5.1 of Python Shade:


Right now, Ubuntu 16.04 have Shade 1.3.0, I'll give it another try, maybe it will work!

Also, I'm already using OS_* variables via Ansible "environment" feature, that's how it works via "shell module" and I'll stick with it by now (i.e., I'm not going to use clouds.yaml file yet).

Thanks again David!
Thiago
Reply all
Reply to author
Forward
0 new messages