Installation

requires_ansible: ">=2.10,<=2.13"

Installation & Dependencies

Prerequisites

  • install python >=3.8

Python dependencies: requirements:

requests>=2.25.0
xmltodict>=0.12.0
docker-compose

Install dependencies:

# upgrade to latest pip3
$ python3 -m pip install --upgrade pip
$ pip install -r requirements.txt
$ pip install ansible

Note

Installing a specific version of ansible:

pip install "ansible>=2.10.3,<2.11", # for latest ansible_core 2.10
pip install "ansible>=4.10.0,<5.0.0", # for latest ansible_core 2.11
pip install "ansible>=5.1.0,<6.0.0" # for latest ansible core 2.12

Install the Solace PubSub+ Ansible Collection

$ ansible-galaxy collection install solace.pubsub_plus

Note

ansible-galaxy command will not overwrite the existing collection if it is already installed. We can change this default behavior by adding a --force command line switch:

$ ansible-galaxy collection install --force solace.pubsub_plus

The official Ansible documentation contains more information about the installation options in the Using collections document.

Set the Python interpreter

Note

Ansible-Solace only works with Python version >=3.8. Most systems come with a Python version 2.x pre-installed in /usr/bin/python.

By setting the environment variable ANSIBLE_PYTHON_INTERPRETER=”path-to-python3” we can tell Ansible which Python interpreter to use.

# manually
$ export ANSIBLE_PYTHON_INTERPRETER={path-to-your-python-3-bin}
# dynamically
$ export ANSIBLE_PYTHON_INTERPRETER=$(python3 -c "import sys; print(sys.executable)")

Ansible Playbook Error when using Python 2.x:

fatal: [local_broker]: FAILED! => {
    "msg": "Unable to import ('ansible_collections', 'solace', 'pubsub_plus', 'plugins', 'module_utils', 'solace_api') due to invalid syntax"
}

Solution: set the ANSIBLE_PYTHON_INTERPRETER={path-to-your-python-3-bin}

Example Installation: MacOs

Sequence:
  • Homebrew

  • Python - choose between Native or a Virtual Environment

  • Ansible

  • Collection

  • Docker Desktop

# Homebrew
# https://brew.sh/
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# check if it was installed correctly
$ brew help

# Python
$ brew install python
$ brew info python
$ brew update && brew upgrade python
$ python3 -V

# upgrade pip
$ python3 -m pip install --upgrade pip
$ pip3 -V

Native

# ansible
$ pip3 install ansible
# check install
$ ansible --version
$ ansible-playbook --version
# check install info
$ pip3 show ansible

# collection dependencies & collection
$ pip3 install -r requirements.txt
$ ansible-galaxy collection install solace.pubsub_plus
# check install path
$ ansible-galaxy collection list

Virtual Env

$ brew install pyenv
# download a Python version
$ pyenv install 3.8.6 # or another version
# bin: ~/.pyenv/versions/3.8.6/bin/python3
$ pip3 install virtualenv

# install the virtual env
$ mkdir my-project
$ cd my-project
$ mkdir venvs
$ cd venvs

# create virtual env
$ virtualenv -p ~/.pyenv/versions/3.8.6/bin/python3 venv3.8.6
# activate virtual env
source venv3.8.6/bin/activate
# check
(venv3.8.6) ...$ python -V
# upgrade pip
(venv3.8.6) ...$ python -m pip install --upgrade pip

# ansible
$ pip install ansible
# check install
$ ansible --version
$ ansible-playbook --version
# check install info
$ pip show ansible

# collection dependencies & collection
$ pip install -r requirements.txt
$ ansible-galaxy collection install solace.pubsub_plus -p venv3.8.6/lib/python3.8/site-packages/ansible_collections/
# [WARNING]: The specified collections path '{root}/my-project/venvs/venv3.8.6/lib/python3.8/site-packages/ansible_collections' is not part ...
# add install path to ANSIBLE_COLLECTIONS_PATH
export ANSIBLE_COLLECTIONS_PATH={root}/my-project/venvs/venv3.8.6/lib/python3.8/site-packages/ansible_collections
# check install path
$ ansible-galaxy collection list

Important

Don’t forget to set ANSIBLE_PYTHON_INTERPRETER={path-to-your-python-3-bin}

Install Docker Desktop if you want to use Solace Broker Services locally.

Example Installation: Ubuntu

Python 3

$ sudo apt update
$ sudo apt -y upgrade
$ sudo apt update

$ sudo apt install python3
$ python3 -V

$ sudo apt install python3-pip
$ sudo python -m pip install --upgrade pip
$ pip -V

Ansible & Solace Collection

$ sudo pip install ansible
$ pip show ansible
$ ansible --version

# collection dependencies & collection
$ sudo pip install -r requirements.txt
$ ansible-galaxy collection install solace.pubsub_plus
# check install path
$ ansible-galaxy collection list

Example Installation: Centos7

Python 3

$ sudo yum install python3
$ sudo yum install libselinux-python3

$ sudo python3 -m pip install --upgrade pip
$ pip -V

Ansible & Solace Collection

$ sudo pip install ansible
$ pip show ansible
$ ansible --version

# collection dependencies & collection
$ sudo pip install -r requirements.txt
$ ansible-galaxy collection install solace.pubsub_plus
# check install path
$ ansible-galaxy collection list