Setting up ubuntu linux for ansible development

Using ansible on ubuntu for the first time

The first task I was shown when following ansible tutorials was editing the hosts file. I ran into a few issues though, hence this post. The solutions I found that helped are documented below:

Install ansible

sudo apt-add-repository -y ppa:ansible/ansible
sudo apt-get update
sudo apt-get install -y ansible

Backups the hosts file

sudo mv /etc/ansible/hosts /etc/ansible/hosts.backup

Edit the hosts  file.

sudo nano hosts

Add your environments and ip addresses, eg:

[local]
127.0.0.1

Get ssh working, and test it can connect to your listed servers

add-username-to-transactions
sudo apt-get install openssh-server

Then test it is working and started:

sudo service ssh start

Run the ansible ping command

ansible all -m ping

Errors

If you get these errors:

Error: Permission denied

Two solutions,

Run the following command with -k

ansible all -m ping -k

This will trigger the password request

OR

Force ask password through the ansible config file:

sudo nano /etc/ansible/ansible.cfg
uncomment:
ask_pass = True

This will also trigger the password request, but by default without needing the -k option.

Then insert your password. You should now get your pong result without the error.

Upgrading flask on a linux server, but getting version errors

Flask database throws errors when trying to upgrade and migrate

The following is a last resort solution for a problematic database, I have yet to find a cleaner solution for this problem.

Delete the existing version of alembic, and start from scratch

source ~/venvs/env.Vodacom-QuoteService/bin/activate

Clear the alembic table

sqlite3 [yourdbfile]
> delete * from alembic_version;

Remove the migrations folder

rm -r migrations/

Initialize the database

python manage.py db init

Upgrade and migrate the database

python manage.py db upgrade
python manage.py db migrate

Restart the service that is using the table.

Might need to rerun these three steps if the database is still not working

python manage.py db upgrade
python manage.py db migrate
(restart your service)