IBM Cloud Docs
Creating an Ansible playbook

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

  1. 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.

  2. 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.

  3. 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.

  4. Upload your Ansible playbook, modules, roles, and collections to your GitHub repository.

  5. Create a Schematics actions.

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.

  1. Browse Ansible Galaxy to find the collection that you want to use in your playbook.
  2. 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 the community.kubernetes collection.
    collections:
      - name: community.kubernetes
        version: 0.9.0
    
  3. Add a collections folder to your GitHub repository that is relative to your playbook, and store the requirements.yml file in this folder as shown in this example.
    ├── collections
            └── requirements.yml
    ├── playbook.yaml
    ├── README.md
    
  4. 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.