Commit 177cac6c authored by Torsten Nielsen's avatar Torsten Nielsen
Browse files

Modifications and fixes to README.md

parent 0aff3b1f
......@@ -10,17 +10,17 @@ Clone this repository to a folder of choice and run the bootstrap script:
$ ./bootstrap-setup.sh
$ rm -fr .git
Use the files `init.vim` and `nanorc` to help setup your editor of choice or just delete them.
Use the files `init.vim`, `nanorc` and `micro_settings.json` to help setup your editor of choice or just delete them. See the section on editors at the end of this document: [Setting up Editors](#setting-up-editors-for-yaml-or-ansible).
## Different ways to install Ansible
Ansible is based on Python (not Perl), but still regarding install, "There's more than one way to do it" [TMTOWTDI](https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it)
There are a number of ways to install Ansible (on Ubuntu):
A couple of ways to install Ansible (on Ubuntu):
- System wide install using (deb) packages (with or without PPA): [Install Ansible on Ubuntu using apt](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-ubuntu)
- Using [Python pip](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-with-pip) to install (globally, as user or in virtual environment)
- Using [Python pip](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-with-pip) to install (either globally, for a user or in a virtual environment)
## System wide installs (all users) using deb-packages
......@@ -29,16 +29,14 @@ Use std. package from Ubuntu (installs version 2.9.6 on focal/20.04 at time of w
$ sudo apt update
$ sudo apt install ansible
[Ansible docs' install guide for Ubuntu](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-ubuntu) also suggests the use of a [PPA](https://launchpad.net/~ansible/+archive/ubuntu/ansible), but [this PPA](https://launchpad.net/~ansible/+archive/ubuntu/ansible) does not support Ubuntu 20.04 aka "Focal", so if you are using a newer Ubuntu version, take at look at the [other PPAs](https://launchpad.net/~ansible) and maybe choose [ansible-3](https://launchpad.net/~ansible/+archive/ubuntu/ansible-3):/
[Ansible docs' install guide for Ubuntu](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-ubuntu) also suggests the use of a [PPA](https://launchpad.net/~ansible/+archive/ubuntu/ansible)
$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible
The [PPA version for Ubuntu 20.04 focal](https://launchpad.net/~ansible/+archive/ubuntu/ansible?field.series_filter=focal) has recently (at time of writing - Nov 2021) been updated to version 4.8, so it's very up to date.
Since Ansible version 2.10 the default install has changed to a more modular install. Where Ansible used to include everything (and the kitchen sink), it now has a lean 'base' install, which has again changed to a 'core' install from version 4.x.x and up. Besides the base (or core) install, there are community and vendor collections, with their own versioning.
Since Ansible version 2.10 the default install has changed to a more modular install. Ansible used to include everything (and the kitchen sink), it now has a lean 'base' or 'core' installation. From version 4.x.x and up it is named 'core'. Besides the base or core install, there are both community and vendor supplied 'collections', with their own versioning.
Se more here: [Ansible 3.0.0 blog post](https://blog.while-true-do.io/ansible-release-3-0-0/) and [Ansible.com blog post](https://www.ansible.com/blog/ansible-3.0.0-qa) or [Ansible 3 Release Notes](https://github.com/ansible-community/ansible-build-data/blob/main/3/CHANGELOG-v3.rst) or [Ansible 4 Release Notes](https://github.com/ansible-community/ansible-build-data/blob/c4ab2b13b7dca1ac14c49e5f56e5185fba500d87/4/CHANGELOG-v4.rst)
......@@ -49,35 +47,30 @@ Se more here: [Ansible 3.0.0 blog post](https://blog.while-true-do.io/ansible-re
### Why use Python virtual environments for Ansible development?
------------------------------------------------------------
Virtual environments create an isolated structure of lightweight directories separated from actual Python system directories. That means you can have different sets of Python environments, each with different versions of modules, files, or configurations. If Ansible is installed using pip, then it can be a hassle to upgrade and the older version (often) has to be uninstalled first.
Virtual environments create an isolated structure of lightweight directories separated from actual Python system directories. That means you can have different sets of Python environments, each with different versions of modules, files, or configurations. If Ansible is installed (globally) using pip, then it can be a hassle to upgrade and the older version (often) has to be uninstalled first.
Ansible is based on Python and leverages many Python modules and plugins. When you test something new, it could require you to update a module, that your Ansible installation depends on. Upgrading a component that your production environment depends on defeats the purpose of testing. Still, you can have different versions of Ansible and other important Python modules in a dedicated test directory with a virtual environment.
## Get set up with Ansible in virtual environment
-------------------------------------------------
Verify the installed Python version and path:
Install the Python programs:
$ sudo apt install python3-pip python3-venv
$ sudo apt install python3-pip python3-venv python3-argcomplete cowsay
$ python3 -V
Python 3.8.10
$ which python3
/usr/bin/python3
Create a directory structure for the virtual environments:
# Default remote (sudo) user - often overwritten in playbook
remote_user = administrator
# Save logfiles
log_path = var/logs/ansible.log
local_tmp = var/tmp
Create a directory structure for Ansible and the virtual environments (`python-vens`). This layout is just one of many ways to set it up - Se [Ansible best practices](https://docs.ansible.com/ansible/2.8/user_guide/playbooks_best_practices.html#directory-layout) for other ways:
host_key_checking = false
retry_files_enabled = false
gather_timeout = 10
$ mkdir -p ~/ansible/python-venvs
$ cd !$
$ cd ~
$ mkdir ansible
$ cd ansible
$ mkdir -p python-venvs collections roles myroles inventories playbooks host_vars group_vars var/{tmp,logs}
$ touch var/logs/ansible.log
$ echo -e "[local]\nlocalhost ansible_connection=local\n" > inventories/hosts
### Create a new Python virtual environment
......@@ -85,8 +78,8 @@ Create a directory structure for the virtual environments:
Create a virtual environment using the `python3 -m venv <environment-name>` command. You can give any name to your Python virtual environment. I want to try the `Ansible 2.9` version, so I named it in a way to identify the directory easily:
$ python3 -m venv ansible2.9.6
$ ls
$ python3 -m venv python-venvs/ansible2.9.6
$ ls python-venvs
ansible2.9.6
......@@ -95,11 +88,11 @@ Create a virtual environment using the `python3 -m venv <environment-name>` comm
After creating a virtual environment, you must enter the environment manually. This changes your active environment variables from your current shell to those required for Python to create a virtual environment:
$ source ansible2.9.6/bin/activate
$ source python-venvs/ansible2.9.6/bin/activate
(ansible2.9.6)$ python3 -V
Python 3.6.8
Next, upgrade the preferred installer program (`pip`) inside your virtual environment:
Next, upgrade the preferred installer program (`pip`) inside your (active) virtual environment:
(ansible2.9.6)$ python3 -m pip install --upgrade pip
......@@ -128,7 +121,7 @@ Ansible was not able to locate a config file - we'll fix that shortly. The Ansib
Anything installed using pip is going in the venv folder for the active virtual environment.
Just like Ansible can be installed in different ways. The Ansible configuration define, where things like inventory, roles and collections should go.
Since Ansible can be installed in different ways. The [Ansible configuration](https://docs.ansible.com/ansible/latest/installation_guide/intro_configuration.html) defines, where things like inventory, roles and collections should go.
## Ansible Configuration
-----------------------
......@@ -142,7 +135,7 @@ While running an Ansible command, the command looks for its configuration file i
An example slightly different from the examples given in [Ansible User Guide](https://docs.ansible.com/ansible/latest/user_guide/sample_setup.html)
If we use '~/ansible' as "current" or "working" directory, when we interact with Ansible, it makes sence to put ```ansible.cfg``` here. This way we could have different subfolders with diffent setups.
If we use '~/ansible' as "current" or "working" directory, when we interact with Ansible, it makes sence to put `ansible.cfg` here. This way we could have different subfolders with diffent setups.
$ cd ~/ansible
$ ls -F
......@@ -151,16 +144,17 @@ If we use '~/ansible' as "current" or "working" directory, when we interact with
Example configuration:
----------------------
$ cat ansible.cfg
Create a new file `ansible.cfg` with contents similar to:
[defaults]
# Paths to search for collections and roles, colon separated
collections_paths = collections
# Paths to search for collections and roles
collections_path = collections
collections_scan_sys_path = false
roles_path = roles:myroles # (optionally) put your own roles in separate folder
roles_path = roles:myroles
# create hosts files under inventories
# Create hosts files under inventories
inventory = inventories
# Default remote (sudo) user - often overwritten in playbook
......@@ -176,15 +170,15 @@ Example configuration:
# A bit of fun
nocows = false
cowselection = unipony-smaller
#cow_selection = unipony-smaller
cow_selection = tux
nocolor = false
[privilege_escalation]
#Change the defaults if needed and/or overwrite in playbook/CLI
#become=True
#become_method=sudo
#become_user=root
#become_ask_pass=False
become = true
become_method = sudo
become_user = root
become_ask_pass = false
# For more example settings
# https://github.com/ansible/ansible/blob/stable-2.11/examples/ansible.cfg
......@@ -296,8 +290,8 @@ Wrap up
Python virtual environments give you the freedom to test whatever version of modules, plugins, and Python packages you need. That includes vital sysadmin software like Ansible, so you can test new Ansible features without disturbing your system install.
Setting up Editors for YAML and/or Ansible
------------------------------------------
Setting up Editors for YAML or Ansible
--------------------------------------
### Vim or Neovim
......@@ -362,4 +356,9 @@ Install cowsay to add a bit of fun to your Ansible output:
|| ||
Next Step:
----------
Hopefully you are now ready to [start using Ansible](https://docs.ansible.com/ansible/latest/user_guide/index.html#getting-started)
Modified from: [Source](https://www.redhat.com/sysadmin/python-venv-ansible?sc_cid=7013a000002pezWAAQ)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment