Ansible Playbook - Hortonworks

Ansible Playbook for Setting Up Hortonworks Hadoop Clusters.

Posted by Aravind Nuthalapati on May 26, 2016

This Ansible Playbook helps setting up Hortonworks Hadoop Cluster with ease.

1. Introduction

Deploying Hortonworks Data Platform (HDP) clusters typically required significant manual configuration using the Ambari GUI. Ansible provided a powerful way to automate server preparation and Ambari-based cluster deployment, enabling faster and more repeatable setups.

Ansible is a radically simple IT automation system. It handles configuration-management, application deployment, cloud provisioning, ad-hoc task-execution, and multinode orchestration - including trivializing things like zero downtime rolling updates with load balancers.

Read the documentation and more at https://ansible.com/

You can find installation instructions here for a variety of platforms. Most users should probably install a released version of Ansible from pip, a package manager or our release repository. Officially supported builds of Ansible are also available. Some power users run directly from the development branch - while significant efforts are made to ensure that devel is reasonably stable, you're more likely to encounter breaking changes when running Ansible this way.

2. Overview of Deployment Architecture

  • Ambari Server: Central management node (e.g., ambari01).
  • Ambari Agents: Installed on all Hadoop nodes (masters, workers).
  • OS: CentOS or RHEL .
  • HDP Version: 2.x.x

3. Ansible Playbook: Server Preparation for HDP


---
- name: Prepare nodes for Hortonworks HDP installation
  hosts: all
  become: yes

  vars:
    java_package: java-1.x.0-openjdk-devel
    hdp_user: hadoop

  tasks:
    - name: Install required packages
      yum:
        name:
          - ""
          - wget
          - ntp
          - unzip
          - curl
        state: present

    - name: Disable SELinux
      selinux:
        state: disabled

    - name: Disable Firewall
      service:
        name: iptables
        state: stopped
        enabled: no

    - name: Configure hostname
      hostname:
        name: ""

    - name: Configure /etc/hosts
      blockinfile:
        path: /etc/hosts
        block: |
          192.168.1.10 ambari01
          192.168.1.11 master01
          192.168.1.12 worker01
          192.168.1.13 worker02

    - name: Start and enable NTP
      service:
        name: ntpd
        state: started
        enabled: yes

4. Ansible Playbook: Install and Configure Ambari Server


---
- name: Install Ambari Server on the management node
  hosts: ambari
  become: yes

  tasks:
    - name: Add Ambari repo
      get_url:
        url: 
        dest: /etc/yum.repos.d/ambari.repo

    - name: Install Ambari server
      yum:
        name: ambari-server
        state: present

    - name: Setup Ambari server
      command: ambari-server setup -s

    - name: Start Ambari server
      service:
        name: ambari-server
        state: started
        enabled: yes

5. Ansible Playbook: Install Ambari Agent on All Nodes


---
- name: Install Ambari Agent
  hosts: all
  become: yes

  tasks:
    - name: Add Ambari repo
      get_url:
        url: 
        dest: /etc/yum.repos.d/ambari.repo

    - name: Install Ambari agent
      yum:
        name: ambari-agent
        state: present

    - name: Configure Ambari server hostname
      lineinfile:
        path: /etc/ambari-agent/conf/ambari-agent.ini
        regexp: '^hostname=.*'
        line: "hostname=ambari01"

    - name: Start Ambari agent
      service:
        name: ambari-agent
        state: started
        enabled: yes

6. Manual Step: Configure HDP Stack via Ambari UI

  1. Log in to http://ambari01:8080 using admin/admin.
  2. Run the HDP Cluster Wizard to:
    • Select HDP version
    • Choose stack components
    • Assign roles to hosts
    • Install and configure the cluster

7. Recommended Directory Structure


hortonworks-ansible/
├── inventory/
│   └── hosts.ini
├── playbooks/
│   ├── prepare-nodes.yml
│   ├── ambari-server-install.yml
│   └── ambari-agent-install.yml
└── group_vars/
    └── all.yml

8. Summary

This Ansible-based setup helped simplify HDP cluster deployment by automating base image configuration and Ambari installation.