Ansible install all required Azure modules - azure

I'm trying a simple thing like creating a Resource group in Azure via an Ansible Playbook, but I need the Azure Python SDK for it. I can't install the SDK with pip install azure because Microsoft doesn't support it anymore, which is completely illogical because Ansible keeps showing ModuleNotFoundError errors every time I execute the playbook, and I have to install them all manually...
Any more efficient way to do this?

I believe you're looking to install Ansible Azure module. So please try the following,
If you already have python and pip installed, use the command pip install ansible[azure], to install Azure modules.
Otherwise Try the following, and see if that helps,
On Windows,
Install Python
Install PIP
Add python and pip installation path to Windows PATH variable
Install Ansible Azure Module: pip install ansible[azure]
On CentOS 7.4,
Install python and pip:
sudo yum check-update; sudo yum install -y gcc libffi-devel python-devel openssl-devel epel-release
sudo yum install -y python-pip python-wheel
Install Ansible Azure Module:
sudo pip install ansible[azure]
On Ubuntu 16.04 LTS,
Install python and pip:
sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev python-pip
Install Ansible Azure Module:
sudo pip install ansible[azure]

Related

Cannot connect to EC2 ubuntu 18.04 instance after upgrading to Python3.9

I am using EC2 Ubuntu 18.04 VM.
Due to CVE-2021-3177, Python needs to be upgraded to the latest version of Python3.9 which would be 3.9.9 currently.
I did that using the deadsnakes option as per the steps mentioned below:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install python3.9
sudo apt-get update
sudo apt upgrade -y
The above ensures that Python3.9.9 is now available. But now python3.6 & python3.9 is available. So next we will use the update-alternatives command to make python3.9 as the default version.
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
Now that alternatives are defined, we will switch to Option 2 as the default option i.e. Python3.9
sudo update-alternatives --config python3
Once done, the following command would point to the latest version.
sudo python3 -V
However, if you use the sudo apt update command, you will see an error stating that
Traceback (most recent call last):
File "/usr/lib/cnf-update-db", line 8, in <module>
from CommandNotFound.db.creator import DbCreator
File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 11, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
E: Sub-process returned an error code
To fix this we will have to add a link using the following command
cd /usr/lib/python3/dist-packages/
sudo ln -s apt-pkg.cpython-{36m,39m}-x86_64-linux-gnu.so
Also below is optional, I tried with and without the following commands
apt purge python3-apt
apt install python3-apt
sudo apt install python3.9-distutils python3.9-dev
Once done following command will now not result in any errors
sudo apt update
This means that the issue is fixed.
But for some reason, I cannot connect with the machine afterwards or if I create an AMI using this I cannot connect to the launched instance using PUTTY or SCP.
The same issue persists with Ubuntu-20.x too.
Appreciate your help.
After upgrading Python, there are issues with the following Python modules that cloud-init depends on, which in turn prevents EC2 from being able to correctly configure your newly booted EC2 instance using cloud-init, and which is why it is inaccessible:
setuptools
urllib3
requests
jinja2
netifaces
You can debug this issue by going to your EC2 instance in the AWS Web Console and clicking:
Actions -> Monitor and troubleshoot -> Get system log
Sometimes it takes a while to update, so click the refresh button until your logs appear. It is easier to read the logs if you download them. This is what helped me solve the issues that I was having.
The following steps resolved the issue for me on Ubuntu 18.04 LTS:
For Ubuntu 20.04 LTS, change the 36m in the symbolic links to 38.
# Add deadsnakes ppa repository
sudo add-apt-repository ppa:deadsnakes/ppa
# Install new python version
sudo apt update
sudo apt install python3.10
# Fix broken apt_inst after python upgrade
sudo ln -s /usr/lib/python3/dist-packages/apt_inst.cpython-36m-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_inst.so
# Fix broken apt_pkg after python upgrade
sudo ln -s /usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_pkg.so
# Make installed python version an alternative with a priority of 2
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
# Make upgraded python version an alternative with a priority of 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
# Reinstall python3-apt
sudo apt remove --purge python3-apt
sudo apt autoclean
sudo apt install python3-apt
# Install required packages
sudo apt install \
build-essential \
python3.10-distutils \
python3.10-venv \
libpython3.10-dev
# Install latest pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3.10 get-pip.py
# Upgrade outdated python libraries that break cloud-init
sudo -i
pip3 install --upgrade setuptools
pip3 install --upgrade urllib3
pip3 install --upgrade requests
pip3 install --upgrade jinja2
pip3 install --upgrade netifaces
pip3 install --upgrade --ignore-installed pyyaml
exit
# Upgrade cloud-init to latest version
sudo apt install --only-upgrade cloud-init
If you use Ansible, it is also affected by the upgrade.
Ansible can be fixed as follows:
Edit /usr/lib/python3/dist-packages/apt/package.py and change the following line:
from collections import Mapping, Sequence
to:
from collections.abc import Mapping, Sequence
It would be useful if the deadsnakes repository could provide an update for python3-apt (eg. python3.10-apt) to solve this issue.
Reference:
https://cloudbytes.dev/snippets/upgrade-python-to-latest-version-on-ubuntu-linux

How to properly install azure-cli in Ubuntu 20.04 using homebrew?

I am trying to install the azure-cli locally from a cloned repository. I successfully installed homebrew on my end. However, when I try to install the azure-cli, the error occurs below at the very end:
From the repository, the instructions work on other devices, both on windows and linux. I don't know why it won't work on my end:
Step 1: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: brew tap-new <name>/azure-cli
Step 3: brew extract azure-cli <name>/azure-cli --version 2.29.2
Step 4: brew install <name>/azure-cli/azure-cli#2.29.2 (This is where error occurs)
*Note: the section is the name of the user of my laptop.
Other part of the installation process I've successfully installed:
Decorator setup:
sudo apt install python3-pip
sudo /usr/bin/pip3 install --system decorator
Azure Functions Core Tools:
npm i -g azure-functions-core-tools#3 --unsafe-perm true
We have ran the below cmdlets in our local environment to install Home brew & azure cli on azure Linux virtual machine which is running with Ubuntu 20.04 image.
Here are the list of Linux cmdlets used:
sudo apt update
sudo apt-get install build-essential
sudo apt install git -y ##installing git
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ##Run Homebrew installation Script
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" ##Add Homebrew to your path
To ensure everything is working correctly to use brew, we can run its command
brew doctor
It may give the warning to install GCC and to remove that simply install it using brew
brew install gcc
To install azure-cli with last version as per the documentation
brew install azure-cli
Here is the output screenshot for reference:
You can refer this blog to install home brew on Ubuntu20.04 linux machine.

Unable to install numpy and pandas in Ubuntu

I already tried
sudo apt-get install build-essential python-dev python-setuptools
sudo apt-get install python-numpy python-scipy
sudo apt-get install libatlas-dev libatlas3gf-base
It was showing Unable to locate package libatlas3gf-base
So I tried
pip install --user --install-option="--prefix=" -U scikit-learn
But it failed. Failure is in the image as shown in this drive link "https://drive.google.com/open?id=1_YZlQYpP5aGGbbEDKzIzsYeiEVIgEmGe".
Try installing with pip
sudo apt-get install python3-pip
sudo pip install pandas or sudo pip3 install pandas
sudo pip install numpy or sudo pip3 install numpy
Try also using a virtual enviroment just in case
apt-get install python-virtualenv
virtualenv testVirtualEnv
cd testVirtualEnv
source bin/activate
Now install dependencies
Virtual enviroments are also a good way of making projects in a more managable way

I'm getting a "command not found" error when trying to install "xgboost" in an Ubuntu 16.04 Virtual Machine

I'm trying to install xgboost in an Ubuntu 16.04 virtual machine.
I'm following this guide and ran this command:
cmake ..
I got this error:
-bash: cmake: command not found
What am I doing wrong and how can I get rid of this error?
Try this:
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:george-edison55/cmake-3.x
sudo apt-get update
sudo apt-get install cmake
UPDATE:
Or you can just use pip:
sudo pip3 install xgboost
It appears you're getting this error because you don't have the cmake command installed, you can fix this by running:
sudo apt install cmake
I don't know if you've missed this but you can also install xgboost using pip (or in your case pip3), like this:
pip3 install xgboost
NOTE: depending on how your user/project is set up you might need to use the sudo command to grant pip3 write privileges to certain (root) directories, if this is the case, you'd use:
sudo pip3 install xgboost
NOTE: if you don't have pip3 installed, you can install it using:
sudo apt install python3 python3-pip
Good luck.

Update ansible (ubuntu server 14)

I installed ansible in Ubunru server 14 using this tutorial http://docs.ansible.com/ansible/intro_installation.html#latest-releases-via-apt-ubuntu
After I checked version of ansible:
$ ansible --version
ansible 1.5.5
But I need 1.9. How to update it?
From Ansible website:
1) First remove installed version of ansible using sudo apt-get remove --purge ansible
2) Now add the correct ppa using sudo apt-add-repository ppa:ansible/ansible
3) Update the package list: sudo apt-get update
4) Install ansible: sudo apt-get install ansible
I had the same issues as you. Above steps worked like a charm :)
Are you sure you installed it correctly? The version in the PPA for 14.04 is 1.9.4-1, so I don't know where 1.5.5 would be coming from.
In any case, you could try erasing ansible (sudo apititude erase ansible should work), and installing ansible with pip as per http://docs.ansible.com/ansible/intro_installation.html#latest-releases-via-pip
(Namely, have pip installed, then run pip install --upgrade ansible)

Resources