tags: run ansible playbook, ansible playbook inventory, ansible playbook, ansible debug, ansible tutorial, playbook, ansible, ansible modules, ansible-playbook
Ansible playbooks are simple configuration management and multi-machine deployment system where we can declare tasks/configurations. it's a file that written in yaml format.
Each playbook is composed of one or more ‘pla ys’ in a list and it execute/launch tasks synchronously or asynchronously.
To help or how to use ansible-playbook command, use -h option
It will show all available option/flags
Now we will write first Ansible Playbook , we can create yaml file under ansible configure directory with any suitable name.
To define targeted hosts in ansible playbook : following syntax
---
- hosts: value
In hosts value we can use one hosts, groups or host patterns, separated by colons for example
To run ansble playbook in all hosts of inventory, we will use "all" keyword, following example
---
- hosts: all
define single hosts : 127.0.0.1 is ansible hosts
---
- hosts: 127.0.0.1
define single remote hosts : 172.17.20.98 is ansible remote hosts
---
- hosts: 172.17.20.98
define multiple hosts in ansible playbook : 127.0.0.1 is localhost & 172.17.20.98 is ansible remote hosts
---
- hosts: 172.17.20.98,127.0.0.1
OR
Thanks
End of this ansible playbook , we need your support so i request you to please like and share this post also comment if something missing by me or give me a suggestion to make more easy/useful.
www.linuxtopic.com
Each playbook is composed of one or more ‘pla ys’ in a list and it execute/launch tasks synchronously or asynchronously.
To help or how to use ansible-playbook command, use -h option
ansible-playbook -h
Get Ansible Playbook Help |
It will show all available option/flags
Now we will write first Ansible Playbook , we can create yaml file under ansible configure directory with any suitable name.
cd /etc/ansible
vi basic.ymlyaml started with "---" then we define group of hosts, variables and tasks.
To define targeted hosts in ansible playbook : following syntax
---
- hosts: value
In hosts value we can use one hosts, groups or host patterns, separated by colons for example
To run ansble playbook in all hosts of inventory, we will use "all" keyword, following example
---
- hosts: all
define single hosts : 127.0.0.1 is ansible hosts
---
- hosts: 127.0.0.1
define single remote hosts : 172.17.20.98 is ansible remote hosts
---
- hosts: 172.17.20.98
define multiple hosts in ansible playbook : 127.0.0.1 is localhost & 172.17.20.98 is ansible remote hosts
---
- hosts: 172.17.20.98,127.0.0.1
OR
---
- hosts: 172.17.20.98 127.0.0.1
To define group name : localhost is ansible hosts group
---
- hosts: localhost
To define remote hosts group : remote is ansible hosts group
---
- hosts: remote
To define multiple group in ansible playbook
---
- hosts: remote,localhost
Define tasks: following syntax
tasks:
- name: Task name
- module:
We will create a file with the help of file module, following playbook example:
---
- hosts: all
tasks:
- name: Create file
file:
state: touch
path: /tmp/myfirstplaybool.txt
How to add remote hosts in ansible inventory - Click Here….
More Help about modules - Click Here...
To check the syntax of a playbook with the --syntax-check flag.
Understating of Ansible Playbook Output
- hosts: 172.17.20.98 127.0.0.1
To define group name : localhost is ansible hosts group
---
- hosts: localhost
To define remote hosts group : remote is ansible hosts group
---
- hosts: remote
To define multiple group in ansible playbook
---
- hosts: remote,localhost
Define tasks: following syntax
tasks:
- name: Task name
- module:
We will create a file with the help of file module, following playbook example:
---
- hosts: all
tasks:
- name: Create file
file:
state: touch
path: /tmp/myfirstplaybool.txt
How to add remote hosts in ansible inventory - Click Here….
More Help about modules - Click Here...
To check the syntax of a playbook with the --syntax-check flag.
ansible-playbook --syntax-check basic.ymlTo run playbook on all add hosts of inventory
ansible-playbook basic.yml
Run Ansible Playbook |
Understating of Ansible Playbook Output
PLAY [ all ] ******************* ( Host/groups/all Information )
TASK [ Gathering Facts ] ********* ( gather facts from hosts )
TASK [ Create file ] ************* ( Task name )
PLAY RECAP ****************** ( Look like summery of execution )
To run playbook on specific host/group of inventory : use -l option
ansible-playbook -l <host/group> basic.ymlFor example we will run this ansible playbook on single host 192.168.3.104, following command we will use:
ansible-playbook -l 192.168.3.104 basic.yml
Execute ansible playbook on single hosts of the inventory |
Thanks
End of this ansible playbook , we need your support so i request you to please like and share this post also comment if something missing by me or give me a suggestion to make more easy/useful.
www.linuxtopic.com