-
Notifications
You must be signed in to change notification settings - Fork 0
/
8_aconditional.txt
100 lines (88 loc) · 2.48 KB
/
8_aconditional.txt
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
install nginx on only redhat based system
-----------------------------------------
- name: playbok for automate script
hosts: all
become: true
tasks:
- name: copy from master to node
yum:
name: nginx
state: present
when: ansible_os_family == "RedHat"
-----------------------------------------------
create one ubuntu server one amaozn linux
-----------------------------------------
- name: playbok for automate script
hosts: all
become: true
tasks:
- name: install epel
command: amazon-linux-extras install epel -y
when: ansible_os_family == "RedHat"
- name: copy from master to node
yum:
name: nginx
state: present
when: ansible_os_family == "RedHat"
it is going to install epel and nginx in amaozn linux2, and it will skip from ubuntu
ansible when condition for ubuntu
----------------------------------
- name: condition playbook
hosts: all
become: true
tasks:
- name: install nginx
apt:
name: nginx
state: present
when: ansible_os_family == "Debian"
-------------------------------------------------------------------------
install multiple packages on ansible by using loop
---------------------------------------------------
- name: condition playbook
hosts: all
become: true
vars:
packages:
- name: nginx
required: true
- name: apache2
required: true
tasks:
- name: install '{{packages}}'
apt:
name: '{{item.name}}'
state: present
loop: '{{packages}}'
when: ansible_os_family == 'Debian'
-----------------------------------------------------------
register module
---------------
it used to capture system data
eg: service up or down, system ip table status
target node should be linux
- name: condition playbook
hosts: all
become: true
tasks:
- name: my task
command: cat /file
register: result
- name: create directory
command: mkdir /created
when: result.stdout.find('ashiq1') != -1
resister module example:
------------------------
create one linex machine an start aapche srever:
- name: condition playbook
hosts: all
become: true
tasks:
- name: my task
command: systemctl status httpd
register: result
when: ansible_os_family == "RedHat"
- name: create directory
shell: echo "yes it is active" > /report
when: result.stdout.find('active') != -1 and
when: ansible_os_family == "RedHat"