Created
March 20, 2021 15:54
-
-
Save dariodip/e4b43b9acee20c277a172ad2c94b417a to your computer and use it in GitHub Desktop.
Ansible for Developers 101
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- apt: | |
name: "apache2" | |
state: present |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: add several users | |
user: | |
name: "{{ item }}" | |
state: present | |
groups: "wheel" | |
loop: | |
- testuser1 | |
- testuser2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: add several users | |
user: | |
name: "{{ item.name }}" | |
state: present | |
groups: "{{ item.groups }}" | |
loop: | |
- { name: 'testuser1', groups: 'wheel' } | |
- { name: 'testuser2', groups: 'root' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: webservers | |
roles: | |
- common | |
- webservers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- yum: | |
name: "httpd" | |
state: present |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment