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 - 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")
Hostname from ansible_facts is: {{ ansible_facts['hostname'] }} Hostname from ansible_facts is: {{ ansible_facts['hostname'] }}
New lines.
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
name: name:
- neofetch - neofetch
- ufw - ufw
state: latest state: present
- name: Active service - name: Active service
ansible.builtin.service: ansible.builtin.service:
name: ufw name: ufw
......
...@@ -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
---
- 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