Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
devops-intern-labs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Nam
devops-intern-labs
Commits
f090b339
Commit
f090b339
authored
Jan 15, 2024
by
Vũ Hoàng Nam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update playbook, improve syntanx.
parent
5ef03cd4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
27 deletions
+45
-27
ansible-fact.yml
Week3&4/ansible-fact.yml
+21
-22
test.j2
Week3&4/files/templates/test.j2
+1
-0
first-playbook.yml
Week3&4/first-playbook.yml
+1
-1
first-template.yml
Week3&4/first-template.yml
+3
-0
prompt.yaml
Week3&4/prompt.yaml
+19
-0
test.yaml
Week3&4/test.yaml
+0
-4
No files found.
Week3&4/ansible-fact.yml
View file @
f090b339
---
---
-
name
:
All about ansible_facts
-
name
:
All about ansible_facts
hosts
:
all
hosts
:
all
# connection: local
tasks
:
-
name
:
Get all ansible_facts
ansible.builtin.debug
:
var
:
ansible_facts
-
name
:
Get distribution
tasks
:
ansible.builtin.debug
:
-
name
:
Get all ansible_facts
var
:
ansible_facts["distribution"]
ansible.builtin.debug
:
var
:
ansible_facts
-
name
:
Check distribution_major_version for testing with When condition.
-
name
:
Get distribution
ansible.builtin.debug
:
ansible.builtin.debug
:
var
:
ansible_facts["distribution"] == "22"
var
:
ansible_facts["distribution"]
-
name
:
When conditions using ansible_facts
-
name
:
Check distribution_major_version for testing with When condition.
ansible.builtin.debug
:
ansible.builtin.debug
:
msg
:
"
Hello
from
{{
ansible_facts.hostname
}}
is
running
{{
ansible_facts.os_family
}}"
var
:
ansible_facts["distribution"] == "22"
when
:
-
ansible_facts.distribution == "Ubuntu"
# AND logic
-
ansible_facts["distribution_major_version"] == "11"
#22 for true
-
name
:
When conditions using ansible_facts
ansible.builtin.debug
:
msg
:
"
Hello
from
{{
ansible_facts.hostname
}}
is
running
{{
ansible_facts.os_family
}}"
when
:
-
ansible_facts.distribution == "Ubuntu"
# AND logic
-
ansible_facts["distribution_major_version"] == "11"
# 22 for true
-
name
:
More When conditions using ansible_facts
-
name
:
More When conditions using ansible_facts
ansible.builtin.debug
:
ansible.builtin.debug
:
msg
:
"
Hello
from
{{
ansible_facts.hostname
}}
is
running
Ubuntu
or
CentOS"
msg
:
"
Hello
from
{{
ansible_facts.hostname
}}
is
running
Ubuntu
or
CentOS"
when
:
(ansible_facts['distribution'] == "CentOS" or ansible_facts['distribution'] == "Ubuntu")
when
:
(ansible_facts['distribution'] == "CentOS" or ansible_facts['distribution'] == "Ubuntu")
Week3&4/files/templates/test.j2
View file @
f090b339
Hostname from ansible_facts is: {{ ansible_facts['hostname'] }}
Hostname from ansible_facts is: {{ ansible_facts['hostname'] }}
New lines.
Week3&4/first-playbook.yml
View file @
f090b339
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
name
:
name
:
-
neofetch
-
neofetch
-
ufw
-
ufw
state
:
lates
t
state
:
presen
t
-
name
:
Active service
-
name
:
Active service
ansible.builtin.service
:
ansible.builtin.service
:
name
:
ufw
name
:
ufw
...
...
Week3&4/first-template.yml
View file @
f090b339
...
@@ -3,12 +3,15 @@
...
@@ -3,12 +3,15 @@
hosts
:
all
hosts
:
all
become
:
true
become
:
true
tasks
:
tasks
:
-
name
:
Check user home directory
-
name
:
Check user home directory
ansible.builtin.debug
:
ansible.builtin.debug
:
var
:
ansible_facts.env.PWD
var
:
ansible_facts.env.PWD
# debugger: always
-
name
:
Write hostname using jinja2
-
name
:
Write hostname using jinja2
ansible.builtin.template
:
ansible.builtin.template
:
src
:
files/templates/test.j2
src
:
files/templates/test.j2
dest
:
'
{{
ansible_facts.env.PWD
}}/msg.txt'
dest
:
'
{{
ansible_facts.env.PWD
}}/msg.txt'
mode
:
preserve
Week3&4/prompt.yaml
0 → 100644
View file @
f090b339
---
-
name
:
Prompt asking
hosts
:
all
vars_prompt
:
-
name
:
username
prompt
:
What is your username?
private
:
false
default
:
user
-
name
:
password
prompt
:
What is your password?
private
:
true
encrypt
:
md5_crypt
tasks
:
-
name
:
Print a message
ansible.builtin.debug
:
msg
:
"
Logging
in
as
{{
username
}}
-
{{
password
}}."
Week3&4/test.yaml
deleted
100644 → 0
View file @
5ef03cd4
---
-
name
:
First
hosts
:
cisco
connection
:
local
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment