Playbooks:(.playbook/.yml/.yaml)
collection of commands and module calls.
Perform one or more tasks(plays)
Playbook syntax(yaml):
---
- hosts: web -->hosts/target server in the inventory file
sudo: yes --> remove this line, if we don't require root access
tasks:
- name: Do a thing
win_feature: "name=Package state=present"
- name: Do another thing
win_service: "name=W3SVC state=restarted"
Output:
Example: iis.yml
---------------------
---
- hosts: web
tasks:
- name: ENsure IIS web server is installed
win_feature:
name=Web Server
state=present
ansible-playbook iis.yml
---
- hosts: web
tasks:
- name: ENsure IIS web server is installed
win_feature:
name=Web Server
state=present
when: ansible_os_family == "Windows" --> or "Linux"
- name: Deploy index file
template:
src: iisstart.j2
dest: c:\inetpub\wwwroot\iisstart.htm
Here, I kept condition in IIS using when.
iisstart.j2
-------------
<html>
<h1>Hello JP, from the {{ ansible_fqdn }}</h1>
</html>
templated iis.html file.
---------------------------------------
Roles: compartmentalized collections of tasks, templates, variables, and more
used to create a function like "web server","email server",or "database server".Which are termed as roles.
mkdir -p roles/webserver/tasks roles/webserver/templates
roles/webserver/tasks/main.yml --default place where ansible looks for tasks to run.
main.yml
---
- name: Ensure IIS webserver is installed
win_feature:
name: Web-Server
state: present
- name: Deploy default iisstart.htm file
template:
src: iisstart.j2
dest: c:\inetpub\wwwroot\iisstart.htm
roles/webserver/templates/iisstart.htm
--------
<html>
<h1>Hi there, {{ ansile_fqdn}} </h1>
</html>
webservers.yml
-----------------
---
- hosts: web
roles: webserver
remove the earlier template without roles, and in root folder of project.
ansible-playbook webservers.yml
collection of commands and module calls.
Perform one or more tasks(plays)
Playbook syntax(yaml):
---
- hosts: web -->hosts/target server in the inventory file
sudo: yes --> remove this line, if we don't require root access
tasks:
- name: Do a thing
win_feature: "name=Package state=present"
- name: Do another thing
win_service: "name=W3SVC state=restarted"
Output:
Example: iis.yml
---------------------
---
- hosts: web
tasks:
- name: ENsure IIS web server is installed
win_feature:
name=Web Server
state=present
ansible-playbook iis.yml
---
- hosts: web
tasks:
- name: ENsure IIS web server is installed
win_feature:
name=Web Server
state=present
when: ansible_os_family == "Windows" --> or "Linux"
- name: Deploy index file
template:
src: iisstart.j2
dest: c:\inetpub\wwwroot\iisstart.htm
Here, I kept condition in IIS using when.
iisstart.j2
-------------
<html>
<h1>Hello JP, from the {{ ansible_fqdn }}</h1>
</html>
templated iis.html file.
---------------------------------------
Roles: compartmentalized collections of tasks, templates, variables, and more
used to create a function like "web server","email server",or "database server".Which are termed as roles.
mkdir -p roles/webserver/tasks roles/webserver/templates
roles/webserver/tasks/main.yml --default place where ansible looks for tasks to run.
main.yml
---
- name: Ensure IIS webserver is installed
win_feature:
name: Web-Server
state: present
- name: Deploy default iisstart.htm file
template:
src: iisstart.j2
dest: c:\inetpub\wwwroot\iisstart.htm
roles/webserver/templates/iisstart.htm
--------
<html>
<h1>Hi there, {{ ansile_fqdn}} </h1>
</html>
webservers.yml
-----------------
---
- hosts: web
roles: webserver
remove the earlier template without roles, and in root folder of project.
ansible-playbook webservers.yml
No comments:
Post a Comment