Firstly, thank-you to all those who attended my Ansible workshop and presentation of Visual Studio Code at the i-UG conference at Northampton in June. It was great to be back presenting and meeting up with friends.
This article is related to this event.
The Power servers for the event, were kindly provided by Rowton IT They arranged four IBM i partitions for me to show all the features of Ansible.
To facilitate the workshop, I didn’t want to waste precious time setting up the servers, so Ansible to the rescue!
For each of the four partitions, I had to create the following;
Set the default PASE shell to be the BASH shell.
Then for a list of ten users, setup the following;
- Create a user profile, additionally setting the home directory and current library
- Create a user library, called the name of the user just created
- Create a home directory on the IFS
- Create a sub-directory, called Ansible off their home directory
- Create a sub-directory, called .ssh off their home directory
- Create a empty authorized_keys file in the users home .ssh directory
- Set the authority on the home directory
- Set the authority on the .ssh directory
- Create an empty .profile file in the users home directory
- In the .profile file, write entries to setup the Open Source path and a default prompt
- Set the authority on the authorized_keys file
As you can see, many steps to perform on the four partitions, lots of scope for errors and typo’s!
Due to the restrictions of using loops with Ansible, I split the environment create into two separate playbooks.
The first playbook is shown in the figure below.
Steps are as follows
- Description of the playbook, use for documentation purposes
- Run the playbook over all the IBM I partitions
- List of users to create
- Set the default PASE shell for all users
- Looping through all the users in step 3, call the playbook ibmi_iug1 with a parameter of the user
Now onto the second playbook, which is doing all the work.
This is shown in the figure below.
Let me explain the stages of this playbook.
- A quick debug message to show the user name being passed from previous playbook. Just for informational purposes only.
- Create a user profile using the name of the user being passed
- Create a library with the user name
- Create a home directory for the user name
- Create an Ansible directory for the user
- Create a .ssh directory
- Create an authorized_keys file on the IFS for the user
- Set authority of the home directory for the user
- Set the authority of the .ssh directory
- Set the authority of the authorized_keys
- Create an empty .profile file for the user
- Set the profile to use a path for the open-source tools and also set the BASH prompt
Let me run the playbook, and show the steps it goes through (For space saving, I’ve restricted it to only run for one user).
All looks good!
Hopefully, this example shows how easy it is to use Ansible to create environments, no typos, or missing steps.
All the examples I have written for this article, and previous ones, can be found on my open-source repository on GitHub, which can be found at https://github.com/formaserve/f_Learning
The two playbooks used throughout this article are called https://github.com/FormaServe/f_Learning/blob/master/Ansible/ibmi_iug.yml
If you have any questions, either on this article, or anything else on the IBM i, use the comments below, or send me a message on twitter @AndyYouens
Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems with over 40 years IBM midrange experience.