Here we are introducing a playbook and how it works with Ansible in Linux servers.
Playbooks can run multiple tasks and jobs and provide some more advanced functionality, it’s used to define deployment and configurations in a single file, using the playbook we can manage our configurations and deployments on remote machines. Ansible playbook config files are written in the simple YAML, the playbooks are designed to be human-readable and developed in a basic text language. As the playbooks expressed in YAML format and have a minimum of syntax, which intentionally tries to not be a programming language or script, but rather a model of a configuration or a process.
A YAML script always starts with “—” and ends with “…”
Apache installation using Ansible playbook :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
--- - hosts: webkul # hosts to be configured sudo: yes # sudo permissions tasks: - name: update apt: update_cache=yes - name: install apache2 apt: name=apache2 state=present - name: restart apache2 service: name=apache2 state=restarted - debug: msg="apache has been installed" ... |
How above codes is working ?
– name: use comand to run “apt-get update”
apt: update_cache=yes : used to update the cache
– name : use to run command “apt-get install apache2”
apt: name=apache2 state=present
– name: to restart apache service
service: name=apache2 state= restart
-debug: msg : used to display installation message.
Be the first to comment.