Using Ansible
Santhosh Balasa
Posted on May 31, 2021
-> Command to validate Ansible playbook syntax:
ansible-playbook <playbook.yml> --syntax-check
-> Sample playbook to run command in localhost:
---
- name:Sample Ansible playbook
hosts: 127.0.0.1
connection: local
tasks:
- name: Display hostname
command: hostname
register: out
- debug: var=out.stdout_lines
-> Run a playbook:
ansible-playbook <playbook.yml>
-> Run multiple commands using playbook:
---
- name: Run multiple commands
hosts: 127.0.0.1
connection: local
vars:
unix_command: ls
tasks:
- name: Display name of the host
command: hostname
register: task1
- name: Execute {{ unix_command }}
command: {{ unix_command }}
register: task2
- debug: var=task1.stdout_lines
- debug: var=task2.stdout_lines
-> For more info refer: https://spacelift.io/blog/ansible-playbooks
💖 💪 🙅 🚩
Santhosh Balasa
Posted on May 31, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
kubernetes Setting Up a Production-Ready Kubernetes Cluster with RKE2 in vSphere Using Terraform
November 29, 2024