forked from discover-devops/my_ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnsible Variables.YAML
81 lines (56 loc) · 2.02 KB
/
Ansible Variables.YAML
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
Ansible Variables
-------------------
We are now going to talk about look at variables in Ansible.
So what are variables, just like any other scripting or programming, language variables are used to store values that varies with different items.
For example, let's say we are trying to perform the same operation of applying patches to
hundreds of servers.
We only need a single playbook for all 100 servers. However, it's the variables that store information about the different host names, usernames or passwords
that are different for each server.
We can define as many variables as required like this. We could also define variables inside the playbook.
To add a variable, we could simply add a "Vars" directive, followed by variables in a key value pair format.
We can also have variables defined in a separate file dedicated for variables. We will learn about this more later when we talk about includes enrols.
- hosts: all
vars:
region:
- ap-south-1
- us-east-1
tasks:
- name: Ansible List variable Example
debug:
msg: "{{ region [1] }}"
vars:
region: [ap-south-1, us-east-1]
https://medium.com/nerd-for-tech/installing-jenkins-using-an-ansible-playbook-2d99303a235f
---
- hosts: target
become: yes
remote_user: ec2-user
become_user: root
tasks:
- name: Download Long Term Jenkins release
get_url:
url: https://pkg.jenkins.io/redhat-stable/jenkins.repo
dest: /etc/yum.repos.d/jenkins.repo
- name: Import jenkins key from url
ansible.builtin.rpm_key:
state: present
key: https://pkg.jenkins.io/redhat-stable/jenkins.io.key
- name: yum update
yum:
name: '*'
state: latest
- name: Install java
yum:
name: java-11-openjdk-devel
state: present
- name: Install jenkins
yum:
name: jenkins
state: latest
- name: daemon-reload to pick up config changes
ansible.builtin.systemd:
daemon_reload: yes
- name: Start jenkins
ansible.builtin.systemd:
name: jenkins
state: started