Convert Figma logo to code with AI

geerlingguy logoansible-for-devops

Ansible for DevOps examples.

8,316
3,434
8,316
107

Top Related Projects

62,307

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.

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.

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.

Molecule aids in the development and testing of Ansible content: collections, playbooks and roles

Quick Overview

The geerlingguy/ansible-for-devops repository is a collection of Ansible playbooks and roles that demonstrate how to use Ansible for various DevOps tasks, such as setting up development environments, deploying applications, and managing infrastructure. It serves as a comprehensive guide for developers and DevOps professionals who want to learn and apply Ansible in their workflows.

Pros

  • Comprehensive Examples: The repository provides a wide range of Ansible playbooks and roles that cover a variety of use cases, making it a valuable resource for learning and reference.
  • Well-Documented: The project includes detailed documentation, including README files and comments within the playbooks, making it easy for users to understand and follow the examples.
  • Active Maintenance: The repository is actively maintained, with regular updates and improvements to the playbooks and roles.
  • Community Support: The project has a large and active community, with contributors providing feedback, bug fixes, and additional examples.

Cons

  • Specific to the Author's Preferences: The playbooks and roles may be tailored to the author's specific preferences and use cases, which may not always align with the needs of every user.
  • Potential Outdated Dependencies: As the project evolves, some of the dependencies or external tools used in the examples may become outdated, requiring users to update the playbooks accordingly.
  • Lack of Customization: While the examples are comprehensive, they may not always provide the level of customization that some users may require for their specific use cases.
  • Large Codebase: The repository contains a significant amount of code, which can be overwhelming for beginners or users who are looking for a more focused set of examples.

Getting Started

To get started with the geerlingguy/ansible-for-devops repository, follow these steps:

  1. Clone the repository to your local machine:

    git clone https://github.com/geerlingguy/ansible-for-devops.git
    
  2. Navigate to the cloned repository:

    cd ansible-for-devops
    
  3. Explore the various directories and playbooks to find the examples that are relevant to your use case. For instance, the drupal directory contains Ansible playbooks for setting up a Drupal development environment.

  4. Review the README files and comments within the playbooks to understand the purpose and usage of each example.

  5. Customize the playbooks as needed to fit your specific requirements, such as updating variable values or adding additional tasks.

  6. Run the playbooks using the Ansible command-line tool:

    ansible-playbook site.yml
    
  7. Monitor the output and troubleshoot any issues that may arise during the execution of the playbooks.

By following these steps, you can quickly get started with the geerlingguy/ansible-for-devops repository and leverage the provided examples to enhance your Ansible skills and automate your DevOps workflows.

Competitor Comparisons

62,307

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.

Pros of Ansible

  • Official repository with comprehensive documentation and extensive community support
  • Includes the core Ansible codebase, allowing for deeper understanding and potential contributions
  • Provides access to the latest features and bug fixes directly from the source

Cons of Ansible

  • Steeper learning curve due to its extensive codebase and features
  • May be overwhelming for beginners or those seeking practical examples for DevOps scenarios
  • Requires more time to navigate and understand the project structure

Code Comparison

Ansible:

def run_playbook(self, playbook_path, inventory_path=None, **kwargs):
    pb = Playbook.load(playbook_path, variable_manager=self.variable_manager, loader=self.loader)
    plays = pb.get_plays()
    
    for play in plays:
        result = self._tqm.run(play)

Ansible for DevOps:

- name: Ensure Apache is installed
  apt:
    name: apache2
    state: present

- name: Copy custom index.html file
  copy:
    src: files/index.html
    dest: /var/www/html/index.html

The Ansible repository contains the core Python codebase, while Ansible for DevOps focuses on practical YAML playbooks and roles for common DevOps scenarios. Ansible for DevOps provides more accessible examples for beginners and those looking to implement DevOps practices quickly, while the Ansible repository offers a deeper dive into the tool's inner workings and allows for more advanced customization.

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

  • Focused specifically on linting Ansible playbooks and roles
  • Actively maintained by the Ansible community
  • Integrates well with CI/CD pipelines for automated checks

Cons of ansible-lint

  • Limited to linting functionality only
  • Steeper learning curve for beginners
  • May require additional setup and configuration

Code comparison

ansible-lint example:

---
- name: Example playbook
  hosts: all
  tasks:
    - name: Install package
      apt:
        name: nginx
        state: present

Ansible for DevOps example:

---
- hosts: web
  become: yes
  vars_files:
    - vars.yml
  tasks:
    - name: Ensure Apache is installed
      apt: name=apache2 state=present

Summary

ansible-lint is a specialized tool for linting Ansible code, offering in-depth analysis and best practice enforcement. It's ideal for teams focused on code quality and standardization.

Ansible for DevOps, on the other hand, is a comprehensive resource for learning and implementing Ansible in real-world scenarios. It provides practical examples and guidance for DevOps practitioners.

While ansible-lint excels in code quality checks, Ansible for DevOps offers a broader educational approach to Ansible usage in DevOps environments. The choice between them depends on whether you need a linting tool or a learning resource for Ansible implementation.

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 detailed job history
  • Supports integration with various cloud providers and external systems

Cons of AWX

  • More complex setup and maintenance compared to simple Ansible playbooks
  • Requires additional resources to run (database, web server, etc.)
  • Steeper learning curve for users new to Ansible

Code Comparison

AWX (using the API):

import tower_cli
job = tower_cli.get_resource('job')
result = job.launch(
    job_template=1,
    extra_vars={'foo': 'bar'}
)

Ansible-for-DevOps (using Ansible directly):

- name: Run a simple playbook
  hosts: all
  vars:
    foo: bar
  tasks:
    - name: Execute a task
      debug:
        msg: "{{ foo }}"

Summary

AWX provides a comprehensive web-based interface for managing Ansible at scale, with advanced features like access control and job scheduling. However, it comes with increased complexity and resource requirements. Ansible-for-DevOps, on the other hand, offers a simpler approach focused on learning and implementing Ansible through practical examples, making it more suitable for individual users or smaller teams getting started with Ansible.

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.

Pros of ansible-examples

  • Official Ansible repository, providing authoritative examples
  • Covers a wide range of use cases and scenarios
  • Regularly updated to reflect current Ansible best practices

Cons of ansible-examples

  • Less structured learning path for beginners
  • Lacks comprehensive explanations for each example
  • May not cover some real-world deployment scenarios

Code Comparison

ansible-examples:

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

- name: Start Apache
  service:
    name: httpd
    state: started

ansible-for-devops:

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

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

The ansible-examples code uses the yum module for Red Hat-based systems, while ansible-for-devops uses apt for Debian-based systems. The latter also includes the enabled: yes option to ensure Apache starts on boot.

ansible-for-devops provides a more structured approach to learning Ansible, with detailed explanations and real-world examples. It's particularly beneficial for DevOps professionals looking to implement Ansible in their workflows. However, ansible-examples offers a broader range of examples and is maintained by the official Ansible team, making it a valuable resource for reference and advanced use cases.

Molecule aids in the development and testing of Ansible content: collections, playbooks and roles

Pros of Molecule

  • Focused on testing Ansible roles and playbooks
  • Provides a standardized framework for role development
  • Supports multiple test scenarios and platforms

Cons of Molecule

  • Steeper learning curve for beginners
  • Requires additional setup and configuration
  • Less comprehensive documentation compared to Ansible for DevOps

Code Comparison

Molecule configuration example:

---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: instance
    image: docker.io/pycontribs/centos:7
    pre_build_image: true

Ansible for DevOps example playbook:

---
- hosts: all
  become: yes
  tasks:
    - name: Ensure Apache is installed
      yum:
        name: httpd
        state: present
    - name: Ensure Apache is running
      service:
        name: httpd
        state: started
        enabled: yes

Summary

Molecule is a specialized testing framework for Ansible roles, offering a structured approach to role development and testing across multiple scenarios. It excels in providing a standardized testing environment but may be more complex for newcomers.

Ansible for DevOps, on the other hand, offers a broader perspective on Ansible usage in DevOps practices. It provides comprehensive examples and explanations, making it more accessible for beginners but less focused on specific testing methodologies.

While Molecule concentrates on role testing, Ansible for DevOps covers a wider range of Ansible applications in real-world scenarios, making it a valuable resource for understanding Ansible's role in DevOps workflows.

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 for DevOps Examples

CI Molecule CI

This repository contains Ansible examples developed to support different sections of Ansible for DevOps, a book on Ansible by Jeff Geerling.

Many examples use Vagrant, VirtualBox, and Ansible to boot and configure VMs on your local workstation.

Not all playbooks follow all of Ansible's best practices, as they illustrate particular Ansible features in an instructive manner.

Manuscript

The book's manuscript is released under the CC BY-SA license, and is publicly available in a separate repository: Ansible for DevOps - Manuscript.

Examples and Chapters in which they're used

Here is an outline of all the examples contained in this repository, by chapter:

Chapter 1

  • N/A

Chapter 2

Chapter 3

  • orchestration: A simple multiple-VM Vagrant configuration and Ansible inventory to allow testing of multi-server orchestration with ansible ad-hoc commands.

Chapter 4

  • drupal: A single-file playbook which configures the LAMP stack on a Linux host and installs Drupal.
  • includes: The same playbook as the drupal example, but using includes to make the playbook more understandable.
  • nodejs: A single-file playbook which configures a Node.js app to run on a Linux host.
  • solr: A single-file playbook which installs Apache Solr on a Linux host.

Chapter 5

  • N/A

Chapter 6

  • nodejs-role: The same playbook as the nodejs example, but using a role to break out the Node.js aspects into a separate nodejs role.
  • galaxy-role-servers: A couple very short playbooks that demonstrate how easy it is to get new servers running leveraging the power of community Ansible Galaxy roles.

Chapter 7

  • test-plugin: A simple test plugin that verifies a given value is representative of the color blue.
  • collection: An example local collection to demonstrate the basic structure of content collections.

Chapter 8

  • dynamic-inventory: Two example dynamic inventory scripts (one in PHP, one in Python) for use with Ansible.

Chapter 9

  • lamp-infrastructure: A multi-server LAMP-based web application infrastructure focused on high-availability and performance for a LAMP-stack app.
  • elk: A two-server example of the Elasticsearch-Logstash-Kibana stack, which uses one server to store and visualize logs centrally, and another server to send logs via Filebeat.
  • gluster: A two-server example of building a fast networked storage setup using Gluster.

Chapter 10

  • deployments: A playbook that deploys a Ruby on Rails application into an environment that runs Passenger and Nginx to handle web requests.
  • deployments-balancer: A playbook that handles zero-downtime deployments to webservers running behind an HAProxy load balancer.
  • deployments-rolling: A playbook that demonstrates rolling deployments to multiple servers for a Node.js app.

Chapter 11

  • security: A playbook containing many security automation tasks to demonstrate how Ansible helps automate security hardening.

Chapter 12

  • jenkins: A playbook that installs and configures Jenkins for CI/CD.

Chapter 13

  • molecule: A Molecule example used for testing and developing an Ansible playbook, or for testing in a Continuous Integration (CI) environment.
  • molecule-ci.yml GitHub Actions workflow: A GitHub Actions workflow which runs the molecule example in a CI environment.

Chapter 14

  • https-self-signed: A playbook that generates self-signed certificates.
  • https-letsencrypt: A playbook that demonstrates automated certificate management with Let's Encrypt and Ansible.
  • https-nginx-proxy: A playbook that demonstrates proxying HTTPS traffic through Nginx to HTTP backends.

Chapter 15

  • docker: Very simple playbook demonstrating Ansible's ability to manage Docker container images.
  • docker-hubot: Slightly more involved example of Ansible's ability to manage and run Docker container images.
  • docker-flask: A sample Flask app built with Ansible playbooks running inside the container.

Chapter 16

  • kubernetes: A playbook that builds a three-node Kubernetes cluster.

License

MIT

Sponsors

  • TinyPilot: An open-source, low-cost KVM over IP for managing your servers.

The above sponsor(s) are supporting Jeff Geerling on GitHub Sponsors. You can sponsor Jeff's work too, to help him continue improving this book and Ansible open source work!

Buy the Book

Ansible for DevOps Cover

Buy Ansible for DevOps for your e-reader or in paperback format.