Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between running the commands ansible and ansible-playbook

Tags:

ansible

When looking at examples for how to define and run ansible scripts, some examples use 'ansible' command to execute the scripts and some examples use 'ansible-playbook' command. But I have been unable to find the difference between them or guidelines regarding which one to use when.

What are the differences between the two commands?

like image 352
adbdkb Avatar asked Nov 06 '20 23:11

adbdkb


People also ask

Is Ansible and Ansible playbook same?

Playbooks are one of the core features of Ansible and tell Ansible what to execute. They are like a to-do list for Ansible that contains a list of tasks. Playbooks contain the steps which the user wants to execute on a particular machine. Playbooks are run sequentially.

What is the difference between Ansible module and playbook?

Ansible modules are standalone scripts that can be used inside an Ansible playbook. A playbook consists of a play, and a play consists of tasks. These concepts may seem confusing if you're new to Ansible, but as you begin writing and working more with playbooks, they will become familiar.

What is Ansible and Ansible playbook?

Ansible Playbooks are lists of tasks that automatically execute against hosts. Groups of hosts form your Ansible inventory. Each module within an Ansible Playbook performs a specific task. Each module contains metadata that determines when and where a task is executed, as well as which user executes it.


1 Answers

Ansible scripts are called playbooks.

By definition

A playbook is a list of plays. A play is minimally a mapping between a set of hosts selected by a host specifier (usually chosen by groups but sometimes by hostname globs) and the tasks which run on those hosts to define the role that those systems will perform. There can be one or many plays in a playbook.

https://docs.ansible.com/ansible/latest/reference_appendices/glossary.html#term-plays

Then, you execute your playbooks with the command ansible-playbook, for example this command execute the playbook test.yml on all servers in your inventory file:

ansible-playbook test.yml -i inventory all

with ansible command you can execute just a tasks against your servers, for example this command execute a task with the module ping on all servers in your inventory file:

ansible -m ping -i inventory all

Then the difference is with ansible-playbook you can execute a playbook with a lot of tasks and with ansible you just can execute a task.

Welcome to ansible world. Red Hat offers an introductory course of ansible you can take it, It'll help you a lot.

https://www.redhat.com/en/services/training/do007-ansible-essentials-simplicity-automation-technical-overview

like image 123
gary lopez Avatar answered Oct 11 '22 13:10

gary lopez