IBM Cloud Docs
Creating an Ansible playbook

Creating an Ansible playbook

To create your Ansible playbook for use with Schematics, follow these prerequisites and the general steps.

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

Ensure that your playbook adheres to the necessary structure and references any required roles and collections for seamless execution in Schematics. For more information, see the Ansible documentation or playbook creation.

Referencing Ansible collections in your playbook

Ansible collections are groups of reusable Ansible resources, such as playbooks, modules, and roles, that you can install and use in your playbook. Collections are available in the Ansible Galaxy repository.

Similar to Ansible roles, collections require a specific folder structure in your GitHub repository.

Follow these steps to use collections in your Schematics playbook

  1. Browse Ansible Galaxy to find the collection that you want to use in your playbook.

  2. Create a requirements.yml file to specify the collections you want to install from Ansible Galaxy. The file structure should follow the Ansible documentation. Here's an example by using the community.kubernetes collection.

    collections:
      - name: community.kubernetes
        version: 0.9.0
    
  3. Add a collections folder to your GitHub repository, relative to your playbook, and place the requirements.yml file inside this folder.

    ├── collections
            └── requirements.yml
    ├── playbook.yaml
    ├── README.md
    
  4. Reference a resource from your collection in your playbook. For more information, see the Ansible documentation. Ensure your playbook's folder structure adheres to the requirements and properly references the collections for seamless execution in Schematics.

Preparing Your Ansible Playbook for Schematics

Before running your Ansible playbook in Schematics, consider the following points:

  • Store your Ansible playbook in a GitHub or GitLab repository.
  • Be aware of the limitations when specifying target hosts for your Ansible resource inventory. For more information, refer to the guidelines on Creating resource inventories for Schematics actions.
  • Ensure that your playbooks are compatible with an Ansible version that is supported in Schematics. To check supported versions, run the ibmcloud schematics version command.
  • Optionally, explore Ansible playbook capabilities in Schematics by using one of the IBM-provided Ansible playbooks.

Next steps

After understanding the prerequisites and preparation steps for your Ansible playbook, the next step is to create a Schematics action. This process involves specifying your Ansible playbook, configuring the resource inventory, and setting up any necessary credentials or variables. Follow the guide on creating a Schematics action to proceed.