📝 | Interested in contributing to this project? Please read our IBM Contributor License Agreement and our Contributing Guide. |
---|
A collection for automating the installation and configuration of IBM MQ using Ansible on Ubuntu machines. Our aim is to make MQ-Ansible extensible for other platforms and more detailed IBM MQ configuration.
This directory contains:
- ansible
roles
for the installation and configuration of IBM MQ. - module
queue_manager.py
to create and configure a queue manager. - playbook
ibmmq.yml
which implements the roles and module.
For a detailed explanation and documentation on how MQ-Ansible works, click here.
ansible
,passlib
andansible-lint
are required on your local machine to run playbooks implementing this collection.- An Ubuntu target machine is required to run MQ.
Ansible installation (Installation guide)
The playbooks and roles in this collection carryout an installation of IBM MQ Advanced on an Ubuntu target machine. The roles have been implemented to set up the required users on the machine, download the software, install and configure IBM MQ, copy over a configurable dev-config.mqsc
file ready to be run on the target machine, and setup and start the web console. Developers can change this file to customise the configuration of their queue managers. Here we use a playbook that calls other playbooks but you can run the roles in playbooks to suit your requirements.
ibmmq.yml - this playbook calls the mq-install and mq-setup playbooks, host names are passed into the imported playbook variable as {{ ansible_play_batch }}
- name: Install and setup IBM MQ
hosts: ['servers']
- name: Run the install playbook
import_playbook: mq-install.yml
- name: Run the setup playbook
import_playbook: mq-setup.yml
mq-install.yml - this playbook installs IBM MQ with the SSH user specified in the inventory
- hosts: "{{ ansible_play_batch }}"
serial: 1
become: false
environment:
PATH: /opt/mqm/bin:{{ ansible_env.PATH }}
roles:
- role: setupusers
vars:
appUid: 909
appGid: 909
mqmHome: /home/mqm
mqmProfile: .profile
- role: downloadmq
vars:
version: 930
mq-setup.yml - this playbook sets up IBM MQ using the 'mqm' user
- hosts: "{{ ansible_play_hosts }}"
serial: 1
become: yes
become_user: mqm
environment:
PATH: /opt/mqm/bin:{{ ansible_env.PATH }}
roles:
- getconfig
- setupconsole
- startconsole
tasks:
- name: Create a queue manager
queue_manager:
qmname:
- 'QM1'
- 'QM2'
state: 'present'
queue_manager.py
- Creates, starts, deletes an IBM MQ queue manager and runs an MQSC file. See the documentation here.
Note: Ansible must be installed on the local machine (Installation guide)
Before running the playbook and implementing our modules and roles for IBM MQ:
-
Check if you have an ssh key pair in order to access the target machines via SSH. Go to the
~/.ssh
directory in your machine and look for the public and private key files e.g.id_rsa
andid_rsa.pub
.cd ~/.ssh
-
If those two files are not in your
ssh
directory, you need to generateid_rsa
andid_rsa.pub
with the following command:ssh-keygen
-
Once the keys have been generated, you need to copy the public key to the target machine's user
ssh
directory.ssh-copy-id -i id_rsa.pub [USER]@[YOUR_TARGET_HOST]
-
To confirm the keys have been copied successfully, connect to your target machine by:
ssh [USER]@[YOUR_TARGET_HOST]
This should connect to your target machine without asking for a password.
-
On your local machine clone this repository.
-
Go to the
ansible_collections/ibm/ibmmq/
directory.cd mq-ansible/ansible_collections/ibm/ibmmq/
-
Create a file
inventory.ini
inside the directory with the following content:[servers] YOUR_HOST_ALIAS ansible_host=YOUR_HOSTNAME ansible_ssh_user=YOUR_SSH_USER YOUR_HOST_ALIAS ansible_host=YOUR_HOSTNAME ansible_ssh_user=YOUR_SSH_USER
- Change
YOUR_HOST_ALIAS
to an alias name that you wish to use e.g.mq-host-1
, you can omit aliases if you prefer - Change
YOUR_HOSTNAME
to your server/hostname, e.g.myserver-1.fyre.com
- Change
YOUR_SSH_USER
to your target machine's SSH user
- Change
The sample playbook ibmmq.yml
installs IBM MQ Advanced with our roles and configures a queue manager with the queue_manager.py
module.
-
Before running the playbook, ensure that you have added the following directory path to the ANSIBLE_LIBRARY environment variable.
-
On Mac:
export ANSIBLE_LIBRARY=${ANSIBLE_LIBRARY}:<PATH-TO>/mq-ansible/ansible_collections/ibm/ibmmq/library
-
On Windows:
set ANSIBLE_LIBRARY=%ANSIBLE_LIBRARY%;<PATH-TO>/mq-ansible/ansible_collections/ibm/ibmmq/library
-
-
Run the following command to execute the tasks within the playbook:
ansible-playbook ./ibmmq.yml -i inventory.ini -e 'ibmMqLicence=accept'
-
The playbook should return the result of
dspmq
with the queue manager created listed. Log into your target machine and check it manually:dspmq
If one of the following errors appears during the run of the playbook, run the following commands according to the problem:
-
Please add this host's fingerprint to your known_hosts file to manage this host.
- Indicates that an SSH password cannot be used instead of a key.Fix:
ssh-keyscan -H [YOUR_HOST] >> ~/.ssh/known_hosts
-
zsh: command not found: dspmq
- Appears that MQ environment variables have not been set.Fix:
. /opt/mqm/bin/setmqenv -s
-
AMQ7077E: You are not authorized to perform the requested operation
- Appears that the user cannot carry out queue manager operations. This occurs when an SSH session to a target machine hasn't been refreshed after the roles have been executed.Fix:
Restart the SSH session.
These playbooks test the functionality and performance of our roles and the queue_manager module in Ansible plays.
To run the test playbooks first:
- copy your
inventory.ini
file to thetests/playbooks
directorycp invenotry.ini tests/playbooks
- go to the
tests/playbooks
directorycd tests/playbooks
- export the modules to your Ansible library
export ANSIBLE_LIBRARY=${ANSIBLE_LIBRARY}:<PATH-TO>/ansible_mq/ansible_collections/ibm/ibmmq/library
- run all test playbooks with
python3 main.py