Informing the IBM Community

An Ansible Environment Setup


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;

  1. Create a user profile, additionally setting the home directory and current library
  2. Create a user library, called the name of the user just created
  3. Create a home directory on the IFS
  4. Create a sub-directory, called Ansible off their home directory
  5. Create a sub-directory, called .ssh off their home directory
  6. Create a empty authorized_keys file in the users home .ssh directory
  7. Set the authority on the home directory
  8. Set the authority on the .ssh directory
  9. Create an empty .profile file in the users home directory
  10. In the .profile file, write entries to setup the Open Source path and a default prompt
  11. 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

  1. Description of the playbook, use for documentation purposes
  2. Run the playbook over all the IBM I partitions
  3. List of users to create
  4. Set the default PASE shell for all users
  5. 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.

  1. A quick debug message to show the user name being passed from previous playbook.  Just for informational purposes only.
  2. Create a user profile using the name of the user being passed
  3. Create a library with the user name
  4. Create a home directory for the user name
  5. Create an Ansible directory for the user
  6. Create a .ssh directory
  7. Create an authorized_keys file on the IFS for the user
  8. Set authority of the home directory for the user
  9. Set the authority of the .ssh directory
  10. Set the authority of the authorized_keys
  11. Create an empty .profile file for the user
  12. 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

The two playbooks used throughout this article are called

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. 

IBM Champion

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.


One response to “An Ansible Environment Setup”

  1. Mike R avatar
    Mike R


    Yet another use for this flexible tool.

Leave a Reply

Your email address will not be published. Required fields are marked *