-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible
52 lines (43 loc) · 1.57 KB
/
ansible
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Playbooks are a combination of Plays
Plays are combination of which remote devices will I be acting on and which actions to take.
Plays can have multiple actions/tasks
### Example playbook might look like this ###
---
- hosts: localhost
vars:
hostname: pynet-rtr1
tasks:
- name: Generate configuration file
template: scr=/home/myuser/ansible/templates/router.j2
dest=/home/myuser/ansible/configs/router.txt
- hosts: webservers
tasks:
- name: do something
some_action
### Ansible Host File ###
/etc/ansible/hosts # this is the default location
# In the file if you want to not enable an ssh connection to local host do the following
[local]
localhost ansible_connection=local
### To execute ansible actions ###
ansible local -m ping # this tests the local group reachability
ansible localhost -m ping # this tests a specific host
ansible-playbook router.yml --check # check tests for any changes that will be made in advanced
### Ansible Roles ### 5 min mark on week 5 ansible 2 video
# Folder Structure
> main_ansible_folder
- site.yml # can be used to execute many different roles
> router # this can be any name to describe the role
> tasks
- main.yml
> templates
- mytemplate.j2
> vars
- main.yml
# Example main.yml for a specific role
---
- name: Generate Config File
template: src=mytemplate.j2 dest=/home/myuser/ansible/configs/{{item.hostname}}.txt
with_items: test_routers
# test_routers definition can be located here
../router/vars/main.yml