AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 790999
Accepted
Sharuzzaman Ahmat Raslan
Sharuzzaman Ahmat Raslan
Asked: 2016-07-21 10:41:04 +0800 CST2016-07-21 10:41:04 +0800 CST 2016-07-21 10:41:04 +0800 CST

ansible:根据ansible_os_family设置变量

  • 772

使用 ansible 2.0.2.0,我想将文件部署到目标服务器。Debian 和 RedHat 系列的目标文件夹不同。

我使用了 set_fact,但似乎它使用了最后定义的,忽略了 when: 选项。

我不想使用变量文件,因为这个变量只在这个特定的剧本中使用

将复制任务复制到 RedHat 和 Debian 中虽然可能,但将来会使维护变得复杂。

下面的剧本在针对 Ubuntu 服务器执行时将失败,因为目标已扩展为 /etc/nrpe.d 用于 RedHat

- set_fact:
  destination: "/etc/nagios/nrpe.d/"
  when: ansible_os_family == "Debian"

- set_fact:
  destination: "/etc/nrpe.d/"
  when: ansible_os_family == "RedHat"

- name: Ensure Nagios custom checks directory exists
  file: path=/usr/local/lib/nagios/plugins state=directory mode=0755

- name: Install check_cpu_steal
  copy: src=eprepo/sysadmin/nagios_checks/check_cpu_steal dest=/usr/local/lib/nagios/plugins/check_cpu_steal mode=0755 owner=root group=root

- name: Install check_cpu_steal command to /etc/nrpe.d
  copy: src=eprepo/sysadmin/files/check_cpu_steal.conf dest="{{ destination }}/check_cpu_steal.conf mode=0644 owner=root group=root"
ubuntu redhat ansible
  • 1 1 个回答
  • 4901 Views

1 个回答

  • Voted
  1. Best Answer
    Sharuzzaman Ahmat Raslan
    2016-07-22T02:11:38+08:002016-07-22T02:11:38+08:00

    我已经解决了我自己的问题。

    本质上,你可以根据os_family设置变量,但你必须正确地做。

    请参阅下面的固定剧本:

    ---
    - name: Set fact for Debian
      set_fact:
        destination: "/etc/nagios/nrpe.d/"
        nrpe_server: "nagios-nrpe-server"
      when: ansible_os_family == "Debian"
    
    - name: Set fact for RedHat
      set_fact:
        destination: "/etc/nrpe.d/"
        nrpe_server: "nrpe"
      when: ansible_os_family == "RedHat"
    
    - name: Ensure Nagios custom checks directory exists
      file: path=/usr/local/lib/nagios/plugins state=directory mode=0755
    
    - name: Install check_cpu_steal nagios check
      copy: src=eprepo/sysadmin/nagios_checks/check_cpu_steal dest=/usr/local/lib/nagios/plugins/check_cpu_steal mode=0755 owner=root group=root
    
    - name: Install check_cpu_steal nrpe config
      copy: src=eprepo/sysadmin/files/check_cpu_steal.conf dest="{{ destination }}/check_cpu_steal.cfg" mode=0644 owner=root group=root
    
    - name: Restart nrpe daemon
      service: name={{ nrpe_server }} state=restarted
    
    • 2

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

  • VirtualBox 上 Ubuntu 的访客优化技巧 [关闭]

  • 外部硬盘上的 virtualbox 虚拟硬盘驱动器(Vista 主机上的 ubuntu 客户机)

  • 如何在 Ubuntu 上挂载 LVM 分区?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve