<a id="ansible-download"></a>

# Download Ansible Playbooks for Confluent Platform

<a id="ansible-download-collection"></a>

## Download Confluent Platform Ansible collection

Starting in Confluent Platform 7.0, Ansible is packaged as an [Ansible Collection](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html).

If you are using Ansible 2.11 or later, download the Ansible Playbooks for Confluent Platform
(Confluent Ansible) collection using the `ansible-galaxy` command as described
in this section.

You can download the Ansible Playbooks for Confluent Platform collection from the following places:

* [Ansible Automation Hub](#ansible-download-collection-from-rh-automation-hub)
* [Ansible Galaxy](#ansible-download-collection-from-ansible-galaxy)
* [GitHub](#ansible-download-collection-from-github)

<a id="ansible-download-collection-from-rh-automation-hub"></a>

### Download the Confluent Platform collection from Ansible Automation Hub

To install Confluent Platform collection from [Ansible Automation Hub](https://console.redhat.com/ansible/automation-hub/repo/published/confluent/platform),
follow the steps in this section.

1. Create the `ansible.cfg` file in your home directory or in your current
   working directory and specify Red Hat Automation Hub as your default
   collection server. For example:
   ```text
   [defaults]
   hash_behaviour=merge
   callback_whitelist=profile_tasks
   remote_tmp=~/.ansible/tmp
   collections_paths=~/.ansible/collections:../../../

   [ssh_connection]
   pipelining = True
   timeout=30

   [galaxy]
   server_list = automation_hub

   [galaxy_server.automation_hub]
   url=https://console.redhat.com/api/automation-hub/content/inbound-confluent/
   auth_url=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
   token=<provide token here>
   ```
2. Now, install the collection from Red Hat Automation Hub by following
   the steps in [Download the Confluent Platform collection from Ansible Galaxy](#ansible-download-collection-from-ansible-galaxy).

For details, see [Getting Started with Red Hat Ansible Automation Hub](https://access.redhat.com/documentation/en-us/red_hat_ansible_automation_platform/1.2/html-single/getting_started_with_red_hat_ansible_automation_hub/index#proc-configure-automation-hub-server).

<a id="ansible-download-collection-from-ansible-galaxy"></a>

### Download the Confluent Platform collection from Ansible Galaxy

To install the latest Confluent collection:
: ```bash
  ansible-galaxy collection install confluent.platform
  ```
  <br/>
  The command downloads the collection into your default collections directory,
  `~/.ansible/collections/ansible_collections/confluent/platform/`.

To install a specific version of the Confluent collection:
: Append the version number along with the package name in the
  `ansible-galaxy` command. For example:

```bash
ansible-galaxy collection install confluent.platform:8.3.0
```

To download the Confluent collection behind a proxy:
: Run the following command with the `https_proxy` environment variable:
  <br/>
  ```bash
  https_proxy=http://proxy-server:port/ \
    ansible-galaxy collection install confluent.platform
  ```

For more details on package installation from Ansible Galaxy, see [Galaxy User
Guide](https://docs.ansible.com/ansible/latest/galaxy/user_guide.html).

<a id="ansible-download-collection-from-github"></a>

### Download the Confluent Platform collection from the GitHub source repository

As an alternative to the recommended methods above, you can install the package
directly from the source repository.

To download Ansible Playbooks for Confluent Platform onto your controller, run the following command. The
command pulls the roles and playbooks into your default collections directory.
Substitute `<branch>` with a `-post` branch of Ansible Playbooks for Confluent Platform. `7.0` or higher
is supported for `<branch>`.

```bash
ansible-galaxy collection install \
  git+https://github.com/confluentinc/cp-ansible.git,<branch>
```

For example, to download the `8.3.0-post` version of
Confluent Ansible, use the following command:

```bash
ansible-galaxy collection install \
  git+https://github.com/confluentinc/cp-ansible.git,8.3.0-post
```

<a id="ansible-build-collection"></a>

#### Build Ansible Playbooks for Confluent Platform collection

An option to install Ansible Playbooks for Confluent Platform collection behind a proxy is to clone the repo
and locally build the collection tarball which you will use to install the
collection. The steps to build and install are:

1. Set up a proxy server:
   ```bash
   git config --global http.proxy http://proxy-server:port/
   git config --global https.proxy http://proxy-server:port/
   ```
2. Create a directory with the following structure:
   ```bash
   mkdir -p <path_to_cp-ansible>/ansible_collections/confluent/platform
   ```

   You can put `<path_to_cp-ansible>` anywhere in your directory
   structure, but the directory structure under
   `<path_to_cp-ansible>` should be set up exactly as specified
   above.
3. Clone the Ansible Playbooks for Confluent Platform repo into the `platform` directory inside the directory
   you created in the previous step:
   ```bash
   git clone https://github.com/confluentinc/cp-ansible \
     <path_to_cp-ansible>/ansible_collections/confluent/platform
   ```

   #### IMPORTANT
   The directory created with the above command must not have the
   world-writable permissions (777). Due to a security risk, Ansible will not
   load the configuration file, `ansible.cfg` if the file is in the
   world-writable directory.

   If you do not use `git clone`, make sure the permissions setting on the
   `cp-ansible` source code is 755.
4. Check out the `8.3.0-post` branch:
   ```bash
   cd <path_to_cp-ansible>/ansible_collections/confluent/platform
   git fetch
   git checkout 8.3.0-post
   ```
5. Create the collection:
   ```bash
   ansible-galaxy collection build
   ```

   The command builds a tarball of the collection in the current directory.
6. Upload the collection tarball to your control node.
7. Install the collection on your Ansible control node:
   ```bash
   ansible-galaxy collection install <the tarball created in the previous step>
   ```

<a id="ansible-hash-merging"></a>

## Configure hash merging

Ansible Playbooks for Confluent Platform requires hash merging to be enabled. Configure the setting in your
[Ansible configuration file](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#ansible-configuration-settings)
as below:

```text
[defaults]
hash_behaviour=merge
```

## Next step

[Prepare Ansible Inventory File to Install Confluent Platform](ansible-prepare.md#ansible-prepare).
