Skip to content

Instantly share code, notes, and snippets.

@eonezhang
Created March 27, 2021 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eonezhang/4b48e0aac4bdd5d926cbb1b1bdf9bf23 to your computer and use it in GitHub Desktop.
Save eonezhang/4b48e0aac4bdd5d926cbb1b1bdf9bf23 to your computer and use it in GitHub Desktop.
ansible获取操作系统版本
# https://www.ipcpu.com/2016/01/ansible-setup-when/
# 通过使用 ansible 的 setup 模块,可以将操作系统的版本变量获取并存储在 ansible 内置的变量中, 可以在脚本中直接引用.
- hosts: webserver
vars:
logserver: 10.127.2.170
gather_facts: True
tasks:
- name: add conf to config files to CentOS6
lineinfile: dest=/etc/rsyslog.conf line="*.* @{{ logserver }}"
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == "6"
- name: restart syslog @CentOS6
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == "6"
service: name=rsyslog state=restarted
- name: add conf to config files to RedHat 5
lineinfile: dest=/etc/syslog.conf line="*.* @{{ logserver }}"
when: ansible_distribution == 'RedHat' and ansible_distribution_major_version == "5"
- name: restart syslog @RedHat 5
when: ansible_distribution == 'RedHat' and ansible_distribution_major_version == "5"
service: name=syslog state=restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment