Menu

gitpiper

Ansible quickstart Cheat Sheet in March 2024

Last Updated: 13 March 2024

README.md

Install Ansible

$ brew install ansible            # OSX
$ [sudo] apt install ansible      # elsewhere

Ansible is available as a package in most OS’s.

See: Installation

Start your project

~$ mkdir setup
~$ cd setup

Make a folder for your Ansible files.

See: Getting started

Creating your files

Inventory file

~/setup/hosts

[sites]
127.0.0.1
192.168.0.1
192.168.0.2
192.168.0.3

This is a list of hosts you want to manage, grouped into groups. (Hint: try
using localhost ansible_connection=local to deploy to your local machine.)

See: Intro to Inventory

Playbook

~/setup/playbook.yml

- hosts: 127.0.0.1
  user: root
  tasks:
    - name: install nginx
      apt: pkg=nginx state=present

    - name: start nginx every bootup
      service: name=nginx state=started enabled=yes

    - name: do something in the shell
      shell: echo hello > /tmp/abc.txt

    - name: install bundler
      gem: name=bundler state=latest

See: Intro to Playbooks

Running

Running ansible-playbook

~/setup$ ls
hosts
playbook.yml

Running the playbook

~/setup$ ansible-playbook -i hosts playbook.yml
PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [127.0.0.1]

TASK: [install nginx] *********************************************************
ok: [127.0.0.1]

TASK: start nginx every bootup] ***********************************************
ok: [127.0.0.1]
...

Read more


338+ more cheat sheets for you in March 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️