jenkins playbook ansible code example
Example 1: ansible playbook webserver
- hosts: "webserver"
tasks:
- name: "installing webserver"
package:
name: "httpd"
state: "present"
- name: "copying index.html"
copy:
src: "~/index.html"
dest: "/var/www/html/"
- name: "starting httpd service"
service:
name: "httpd"
state: "started"
- name: "stopping firewalld service"
service:
name: "firewalld"
state: "stopped"
Example 2: ansible example playbook
---
- name: update web servers
hosts: webservers
remote_user: root
tasks:
- name: ensure apache is at the latest version
yum:
name: httpd
state: latest
- name: write the apache config file
template:
src: /srv/httpd.j2
dest: /etc/httpd.conf
- name: update db servers
hosts: databases
remote_user: root
tasks:
- name: ensure postgresql is at the latest version
yum:
name: postgresql
state: latest
- name: ensure that postgresql is started
service:
name: postgresql
state: started