Skip to content

Instantly share code, notes, and snippets.

@dariodip
Created March 20, 2021 15:54
Show Gist options
  • Save dariodip/e4b43b9acee20c277a172ad2c94b417a to your computer and use it in GitHub Desktop.
Save dariodip/e4b43b9acee20c277a172ad2c94b417a to your computer and use it in GitHub Desktop.
Ansible for Developers 101
- apt:
name: "apache2"
state: present
tasks:
- name: add cache dir
file:
path: /opt/cache
state: directory
- name: install nginx
yum:
name: nginx
state: latest
notify: restart nginx
handlers:
- name: restart nginx
service:
name: nginx
state: restarted
[control]
control ansible_host=10.45.21.2
[web]
node1 ansible_host=10.43.21.0
node2 ansible_host=10.43.21.1
node3 ansible_host=10.43.21.2
node4 ansible_host=10.43.21.3
[haproxy]
haproxy ansible_host=10.43.20.0
[all:vars]
ansible_user=vagrant
ansible_ssh_private_key_file=~/.vagrant.d/private_key
[web:vars]
ansible_user=dario
- name: add several users
user:
name: "{{ item }}"
state: present
groups: "wheel"
loop:
- testuser1
- testuser2
- name: add several users
user:
name: "{{ item.name }}"
state: present
groups: "{{ item.groups }}"
loop:
- { name: 'testuser1', groups: 'wheel' }
- { name: 'testuser2', groups: 'root' }
---
- name: install and start apache
hosts: web
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: install httpd
yum: pkg=httpd state=latest
- name: write the apache config file
template: src=//localhost:1313/srv/httpd.j2 dest=/etc/httpd.conf
- name: start httpd
service: name=http state=started
---
- hosts: webservers
roles:
- common
- webservers
tasks:
- name: add cache dir
file:
path: /opt/cache
state: directory
- name: install nginx
yum:
name: nginx
state: latest
- name: restart nginx
service:
name: nginx
state: restarted
- yum:
name: "httpd"
state: present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment