0% found this document useful (1 vote)
2K views2 pages

Ansible Frescoplay

The document provides examples of using loops, conditionals (when clause), and playbooks in Ansible. It shows: 1) Using a loop (with_items) to install multiple packages (mongodb, apache2, sqlite3, git) on a server. 2) Using a when conditional to copy a file to a directory only if the file does not already exist in that location. 3) Three playbooks - one to install and start Nginx, another for PostgreSQL, and a third that runs the first two playbooks. The playbooks demonstrate installing and configuring packages and services on servers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
2K views2 pages

Ansible Frescoplay

The document provides examples of using loops, conditionals (when clause), and playbooks in Ansible. It shows: 1) Using a loop (with_items) to install multiple packages (mongodb, apache2, sqlite3, git) on a server. 2) Using a when conditional to copy a file to a directory only if the file does not already exist in that location. 3) Three playbooks - one to install and start Nginx, another for PostgreSQL, and a third that runs the first two playbooks. The playbooks demonstrate installing and configuring packages and services on servers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Ansible Sibelius Module Explained

---
- name: Stop and Start ssh
service:
name: ssh
state: stopped
- name: Stop and Start ssh
service:
name: ssh
state: started

ansible-playbook -i localhost mainplaybook.yml

LOOPS:

ansible loops- ansible siblius -working

loops
type the below in the defaults/mail.yml
---
mongo_packages:
- apache2
- sqlite3
- git

type the below in tasks/main.yml

---
- name: Install mongodb
yum:
name: "{{ item }}"
state: present
with_items: "{{ mongo_packages }}"

Ansible When Clause:

#Create the directory using the adhoc command

step1 : run this in terminal

ansible localhost -m ansible.builtin.file -a "dest=/home/user/test mode=755


state=directory"

step :2 create a file named simplefile.txt

touch simplefile.txt

click File->new file

name the file as simplefile.txt


step :3 main.yml

---
- name: check destination
stat:
path: /home/user/test/simplefile.txt
register: p
- name: copy file if not exists
command: mv /projects/challenge/simplefile.txt /home/user/test
when: p.stat.exists == False

Ansible Sibelius Handon


Ansible sibelius - Try It Out-Write A Playbook

- name: Install nginx


apt:
name: nginx
state: latest

- name: Start NGiNX


service:
name: nginx
state: started

- name: Install PostgreSQL


apt:
name: postgresql
state: latest

- name: Start PostgreSQL


service:
name: postgresql
state: started

then run
ansible-playbook -i myhosts test.yml
ansible-playbook -i myhosts mainplaybook.yml
ansible-playbook -i myhosts master_playbook.yml

You might also like