Skip to content

Instantly share code, notes, and snippets.

@lrvick
Created May 9, 2018 18:04
Show Gist options
  • Save lrvick/fa44015cf56586de1214f99e04d26103 to your computer and use it in GitHub Desktop.
Save lrvick/fa44015cf56586de1214f99e04d26103 to your computer and use it in GitHub Desktop.
Ansible pattern for multi-os configuration
---
- hosts: all
become: yes
become_user: "{{ lookup('env','SUDO_USER') }}"
tasks:
- name: Display OS Details
block:
- debug:
var: ansible_distribution
verbosity: 1
- debug:
var: ansible_distribution_major_version
verbosity: 1
- name: Display all variables/facts known for a host
debug:
var: hostvars[inventory_hostname]
verbosity: 4
- name: Include OS specific tasks
include_tasks: "{{ os_item }}"
with_first_found:
- "tasks/{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version}}.yml"
- "tasks/{{ ansible_distribution | lower }}.yml"
tags: vars
loop_control:
loop_var: os_item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment