Creating an Ansible playbook
Follow these prerequisites and general steps to create your Ansible playbook. For detailed information about how to structure your playbook, see the Ansible documentation or playbook creation.
Want to use existing Ansible playbooks to get started? Try out one of the IBM-provided Ansible playbooks or browse existing Ansible collections and roles in Ansible Galaxy
-
Create your resource inventory where you want to run your Ansible playbook. You can also use the built-in Terraform capabilities in Schematics to provision your target hosts. For more information, see Infrastructure deployment with Schematics workspaces.
-
Create your Ansible playbook. Use one of the IBM-provided playbooks to get started or browse Ansible Galaxy to find existing roles and collections. You can then reference these roles and collections in your playbook.
-
Create a repository in GitHub or GitLab, and build the Ansible playbook directory and file structure. Depending on whether you use Ansible roles and collections, this directory structure might vary. To find a sample structure, see this sample playbook.
-
Upload your Ansible playbook, modules, roles, and collections to your GitHub repository.
Referencing Ansible collections in your playbook
Ansible collections group different reusable Ansible resources, such as playbooks, modules, and roles so that you can install them and use them in your playbook. Collections are stored in the Ansible Galaxy repository.
Similar to Ansible roles, collections require a specific folder structure in your GitHub repository.
-
Browse Ansible Galaxy to find the collection that you want to use in your playbook.
-
Create a
requirements.yml
file where you specify the collections that you want to install from Ansible Galaxy. For more information about how to structure this file, see the Ansible documentation. The following example uses thecommunity.kubernetes
collection.collections: - name: community.kubernetes version: 0.9.0
-
Add a
collections
folder to your GitHub repository that is relative to your playbook, and store therequirements.yml
file in this folder as shown in this example.├── collections └── requirements.yml ├── playbook.yaml ├── README.md
-
Reference a resource from your collection in your playbook. For more information, see the Ansible documentation
Preparing your Ansible playbook to run in Schematics
To prepare your Ansible playbook for Schematics, review the following considerations.
- Your Ansible playbook must be stored in a GitHub or GitLab repository.
- You are limited in how you can specify the target hosts for your Ansible resource inventory. For more information, see Creating resource inventories for Schematics actions.
- All playbooks must be compatible to run with an Ansible version that is supported in Schematics. To find supported versions run
ibmcloud schematics version
command. - Optionally, to explore Ansible playbook capabilities in Schematics. You can try to use one of the IBM-provided Ansible playbooks.