Operations 2 min read

Using Ansible to Detect CentOS Version and Architecture

This article demonstrates how to use Ansible playbooks and simple shell scripts to identify the CentOS major version and system architecture, while also providing promotional links to related DevOps and Kubernetes tutorials.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Using Ansible to Detect CentOS Version and Architecture

Follow the blue "DevOps Architecture Practice" link to receive daily technical pushes at 07:30, and share the article to your moments for updates.

The following Ansible playbook shows how to determine whether the target host is running CentOS 8 or CentOS 7:

- hosts: all tasks: - name: sjg when 8 shell: echo "Centos8" register: result - debug: var=result when: ansible_distribution_major_version == "8" - name: sjg when 7 shell: echo "Centos7" register: result - debug: var=result when: ansible_distribution_major_version == "7"

Additional checks can be performed, such as verifying the distribution name ( ansible_distribution == "CentOS" ) and the CPU architecture ( ansible_architecture == "x86_64" ).

Alternatively, a plain shell script can be used to detect CentOS by examining /etc/redhat-release :

cat /etc/redhat-release | grep 'CentOS' >/dev/null 2>&1 if [ $? -eq 0 ]; then echo "Centos" else echo "Not Centos" fi

--- End of the technical snippet ---

Recommended reading includes a series of links to tutorials on Kubernetes deployment, monitoring, scaling, Ansible role usage, and other DevOps practices.

DevOpsCentOSshell scriptAnsibleVersion Detection
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.