Reputation: 1
I am new to Ansible, I got the task to display below format from host machine using ansible playbook. output - RHEL 7.7 (x86_64)
I have written using shell script - os_version=$(cat $RHAT_RELEASE 2>/dev/null | awk '{printf("%s ", $0)};END{printf("\n")}' | sed 's/Red Hat Enterprise Linux Server release/RHEL/g' | cut -f1 -d'(' | sed 's/ +$//g')
RHEL_VERSION=$(echo $os_version | awk '{print $2}' | cut -f1 -d'.')
RHEL_MINOR=$(echo $os_version | awk '{print $2}' | cut -f2 -d'.')
RHEL_ARCH=$(uname -i)
But as per requirement, I should format the output using ansible_distribution or ansible_facts
Please help in writing ansible playbook
Upvotes: 0
Views: 1575
Reputation: 3728
You can combine some of the ansible_facts
variables, e.g.
---
- name: Print Distribution Info
hosts: localhost
tasks:
- debug:
msg: "{{ ansible_distribution }} {{ ansible_distribution_version }} ({{ ansible_architecture }})"
Upvotes: 1