Commit f090b339 authored by Vũ Hoàng Nam's avatar Vũ Hoàng Nam

Update playbook, improve syntanx.

parent 5ef03cd4
---
- name: All about ansible_facts
hosts: all
tasks:
- name: Get all ansible_facts
ansible.builtin.debug:
var: ansible_facts
# connection: local
- name: Get distribution
ansible.builtin.debug:
var: ansible_facts["distribution"]
tasks:
- name: Get all ansible_facts
ansible.builtin.debug:
var: ansible_facts
- name: Check distribution_major_version for testing with When condition.
ansible.builtin.debug:
var: ansible_facts["distribution"] == "22"
- name: Get distribution
ansible.builtin.debug:
var: ansible_facts["distribution"]
- 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: Check distribution_major_version for testing with When condition.
ansible.builtin.debug:
var: ansible_facts["distribution"] == "22"
- 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
ansible.builtin.debug:
msg: "Hello from {{ ansible_facts.hostname }} is running Ubuntu or CentOS"
when: (ansible_facts['distribution'] == "CentOS" or ansible_facts['distribution'] == "Ubuntu")
- name: More When conditions using ansible_facts
ansible.builtin.debug:
msg: "Hello from {{ ansible_facts.hostname }} is running Ubuntu or CentOS"
when: (ansible_facts['distribution'] == "CentOS" or ansible_facts['distribution'] == "Ubuntu")
Hostname from ansible_facts is: {{ ansible_facts['hostname'] }}
New lines.
......@@ -18,7 +18,7 @@
name:
- neofetch
- ufw
state: latest
state: present
- name: Active service
ansible.builtin.service:
name: ufw
......
......@@ -3,12 +3,15 @@
hosts: all
become: true
tasks:
- name: Check user home directory
ansible.builtin.debug:
var: ansible_facts.env.PWD
# debugger: always
- name: Write hostname using jinja2
ansible.builtin.template:
src: files/templates/test.j2
dest: '{{ ansible_facts.env.PWD }}/msg.txt'
mode: preserve
---
- 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 }}."
---
- name: First
hosts: cisco
connection: local
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment