Gunakan salah satu ekspresi Jinja2 berikut:
{{ hostvars[inventory_hostname].ansible_distribution }}
{{ hostvars[inventory_hostname].ansible_distribution_major_version }}
{{ hostvars[inventory_hostname].ansible_distribution_version }}
di mana:
hostvars
danansible_...
sudah terpasang dan dikumpulkan secara otomatis oleh Ansibleansible_distribution
adalah host yang sedang diproses oleh Ansible
Misalnya, dengan asumsi Anda menjalankan peran Ansible test_role
terhadap host host.example.com
menjalankan distribusi CentOS 7:
---
- debug:
msg: "{{ hostvars[inventory_hostname].ansible_distribution }}"
- debug:
msg: "{{ hostvars[inventory_hostname].ansible_distribution_major_version }}"
- debug:
msg: "{{ hostvars[inventory_hostname].ansible_distribution_version }}"
akan memberi Anda:
TASK [test_role : debug] *******************************************************
ok: [host.example.com] => {
"msg": "CentOS"
}
TASK [test_role : debug] *******************************************************
ok: [host.example.com] => {
"msg": "7"
}
TASK [test_role : debug] *******************************************************
ok: [host.example.com] => {
"msg": "7.5.1804"
}
Secara terstruktur:
- hosts: all
become: no
vars:
output_file: os.csv
tasks:
- block:
# For permisison setup.
- name: get current user
command: whoami
register: whoami
run_once: yes
- name: clean file
copy:
dest: "{{ output_file }}"
content: 'hostname,distribution,version,release'
owner: "{{ whoami.stdout }}"
run_once: yes
- name: fill os information
lineinfile:
path: "{{ output_file }}"
line: "{{ ansible_hostname }},\
{{ ansible_distribution }},\
{{ ansible_distribution_version }},\
{{ ansible_distribution_release }}"
# Tries to prevent concurrent writes.
throttle: 1
delegate_to: localhost
Membuat file yang dipisahkan koma bernama os.csv
dalam folder eksekusi. Anda dapat menggunakan variabel apa pun yang ingin Anda edit line:
.
Bagaimana saya bisa menginstal Anaconda terbaru dengan wget
Apa efek pengaturan soket linux - prioritas tinggi?