Reputation: 243
Module not loaded error running ansible on Azure.
Trying to install ansible on Azure and run some test code
Trying to test some deployment installing ansible on an Azure VM. --installed following packages in the VM --Azure specific --install packages for azure python SDK modules
sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev python-pip
--install ansible packeges
sudo pip install ansible[azure]
sudo pip install msrestazure
sudo pip install msrest
When trying creating a resource group, get an error with library not loaded error
---
- hosts: localhost
connection: local
tasks:
- name: Create resource group
azure_rm_resourcegroup:
name: ansible-rg
location: centralus
register: rg
- debug:
var: rg
Getting the error,
TASK [Create resource group] ************************************************************************************************************* An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named typing fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (msrestazure) on 's Python /usr/bin/python. Please read module documentation and install in the appropriate location"}
PLAY RECAP
Create the resource group
Upvotes: 0
Views: 2418
Reputation: 31414
Generally, if you use the python2 and execute the command sudo pip install
then it will install the packages in the path /usr/local/lib/python2.7/dist-packages. But if you change something of the environment and you do not know, there will be some errors and you also do not know.
So I will suggest you use the virtual environment, it will not affect your real environment. So follow the steps here:
sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev python-pip
sudo pip install virtualenv
sudo mkdir ansible
sudo virtualenv ansible
cd ansible
source bin/activate
Now the virtual environment is ready and you can install the ansible in it.
sudo pip install ansible[azure]
Then create the credentials file in the path ~/.azure/ with your service principal. And when you install the ansible[azure]
, the packages msrest
and msrestazure
is already installed. So you do not need to install them again. Then you can try to create the resource group again.
Upvotes: 2