Convert Figma logo to code with AI

ansible logoansible-examples

A few starter examples of ansible playbooks, to show features and how they work together. See http://galaxy.ansible.com for example roles from the Ansible community for deploying many popular applications.

11,606
7,649
11,606
93

Top Related Projects

Ansible for DevOps examples.

Training Course for Ansible Automation Platform

ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you

13,861

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.

Quick Overview

The ansible/ansible-examples repository is a collection of example playbooks and roles for Ansible, an open-source automation tool. It provides practical demonstrations of Ansible's capabilities, covering various use cases and best practices for infrastructure management and application deployment.

Pros

  • Comprehensive collection of real-world examples
  • Covers a wide range of scenarios and technologies
  • Serves as a valuable learning resource for Ansible users
  • Regularly updated to reflect current best practices

Cons

  • Some examples may be outdated or not follow the latest Ansible recommendations
  • Limited documentation for individual examples
  • May not cover all possible use cases or advanced scenarios
  • Requires basic Ansible knowledge to fully understand and implement

Code Examples

  1. Basic playbook structure:
---
- name: Example playbook
  hosts: webservers
  become: yes
  tasks:
    - name: Ensure Apache is installed
      ansible.builtin.yum:
        name: httpd
        state: present

This example shows a simple playbook that installs Apache on webservers.

  1. Using roles:
---
- name: Configure web servers
  hosts: webservers
  roles:
    - common
    - webserver

This playbook demonstrates how to use roles to organize and reuse Ansible code.

  1. Handling variables:
---
- name: Deploy application
  hosts: app_servers
  vars:
    app_version: "1.2.3"
  tasks:
    - name: Deploy app
      ansible.builtin.template:
        src: app.conf.j2
        dest: /etc/app/app.conf
      vars:
        port: 8080

This example shows how to use variables at different levels in a playbook.

Getting Started

To use these examples:

  1. Clone the repository:

    git clone https://github.com/ansible/ansible-examples.git
    
  2. Navigate to the desired example directory:

    cd ansible-examples/wordpress-nginx
    
  3. Review the README.md file in the example directory for specific instructions.

  4. Run the playbook:

    ansible-playbook -i hosts site.yml
    

Note: Ensure you have Ansible installed and configured before running the examples.

Competitor Comparisons

Ansible for DevOps examples.

Pros of ansible-for-devops

  • More up-to-date and actively maintained
  • Comprehensive examples covering modern DevOps practices
  • Includes Vagrant configurations for easy testing

Cons of ansible-for-devops

  • Less diverse range of examples compared to ansible-examples
  • Focused on specific use cases rather than general-purpose examples
  • May be overwhelming for absolute beginners

Code Comparison

ansible-examples:

- name: Install Apache
  yum: name=httpd state=present

- name: Start Apache Service
  service: name=httpd state=started enabled=yes

ansible-for-devops:

- name: Install Apache
  apt:
    name: apache2
    state: present

- name: Ensure Apache is running
  systemd:
    name: apache2
    state: started
    enabled: yes

The code snippets show similar tasks but with different syntax and package managers. ansible-for-devops uses more modern Ansible syntax and focuses on Debian-based systems, while ansible-examples uses older syntax and is centered around Red Hat-based systems.

ansible-for-devops provides more detailed examples with explanations, making it easier for DevOps practitioners to understand and implement. However, ansible-examples offers a broader range of scenarios, which can be beneficial for learning various Ansible use cases.

Both repositories serve as valuable resources for learning Ansible, with ansible-for-devops being more suitable for those focusing on modern DevOps practices, and ansible-examples providing a wider array of general-purpose examples.

Training Course for Ansible Automation Platform

Pros of workshops

  • More comprehensive and structured learning experience
  • Regularly updated with new content and examples
  • Includes hands-on labs and exercises for practical application

Cons of workshops

  • Larger repository size, potentially overwhelming for beginners
  • Requires more setup and resources to run workshops
  • May contain more complex scenarios than necessary for basic learning

Code Comparison

workshops:

- name: Create Azure VM
  azure_rm_virtualmachine:
    resource_group: myResourceGroup
    name: myVM
    vm_size: Standard_DS1_v2
    admin_username: azureuser
    ssh_public_keys:
      - path: /home/azureuser/.ssh/authorized_keys
        key_data: "{{ ssh_public_key }}"

ansible-examples:

- name: Ensure Apache is installed
  yum:
    name: httpd
    state: present

- name: Ensure Apache is running
  service:
    name: httpd
    state: started
    enabled: yes

The workshops repository provides more advanced examples, such as cloud provisioning, while ansible-examples focuses on simpler, foundational tasks like package management and service control.

ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you

Pros of ansible-lint

  • Focuses on linting and code quality, helping to identify and fix issues in Ansible playbooks
  • Actively maintained with regular updates and improvements
  • Integrates well with CI/CD pipelines for automated checks

Cons of ansible-lint

  • Limited in scope compared to ansible-examples, which covers a wider range of Ansible use cases
  • Steeper learning curve for beginners who may benefit more from practical examples
  • May produce false positives or overly strict warnings in some cases

Code Comparison

ansible-lint example:

- name: Install packages
  apt:
    name: "{{ item }}"
    state: present
  loop:
    - nginx
    - postgresql

ansible-examples equivalent:

- name: Install packages
  apt:
    name:
      - nginx
      - postgresql
    state: present

The ansible-lint version uses a loop, which is generally discouraged for simple package installations. The ansible-examples version uses the recommended syntax for multiple package installations.

13,861

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.

Pros of AWX

  • Provides a web-based user interface for managing Ansible playbooks and inventories
  • Offers role-based access control and job scheduling capabilities
  • Integrates with various cloud providers and version control systems

Cons of AWX

  • More complex setup and maintenance compared to simple example playbooks
  • Requires additional system resources to run
  • Steeper learning curve for users new to Ansible

Code Comparison

AWX (from awx/main/models/unified_jobs.py):

class UnifiedJob(PolymorphicModel, CommonModelNameNotUnique):
    class Meta:
        app_label = 'main'

    STATUS_CHOICES = [
        ('new', _('New')),
        ('pending', _('Pending')),
        ('waiting', _('Waiting')),
        ('running', _('Running')),
        ('successful', _('Successful')),
        ('failed', _('Failed')),
        ('error', _('Error')),
        ('canceled', _('Canceled')),
    ]

Ansible-examples (from lamp_simple/roles/web/tasks/main.yml):

- name: Install apache and php
  yum: name={{ item }} state=present
  with_items:
   - httpd
   - php
   - php-mysql

The AWX code snippet shows a more complex Python class structure for job management, while the Ansible-examples code is a simple YAML playbook for installing packages.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Ansible Examples

This repository contains examples and best practices for building Ansible Playbooks.