【问题标题】:How Can I display specific formats from ansible_facts using ansible playbook?如何使用 ansible playbook 从 ansible_facts 显示特定格式?
【发布时间】:2021-07-22 01:00:24
【问题描述】:

我是 Ansible 的新手,我的任务是使用 ansible playbook 从主机显示以下格式。 输出 - RHEL 7.7 (x86_64)

我使用 shell 脚本编写过 - os_version=$(cat $RHAT_RELEASE 2>/dev/null | awk '{printf("%s ", $0)};END{printf("\n")}' | sed 's/Red Hat Enterprise Linux Server 版本/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)

但根据要求,我应该使用 ansible_distribution 或 ansible_facts 格式化输出

请帮助编写 ansible playbook

【问题讨论】:

  • 需要输出 - RHEL 7.7 (x86_64)

标签: ansible ansible-facts


【解决方案1】:

您可以组合一些ansible_facts 变量,例如

---
- name: Print Distribution Info
  hosts: localhost
  tasks:

    - debug:
        msg: "{{ ansible_distribution }} {{ ansible_distribution_version }} ({{ ansible_architecture }})"

【讨论】:

    猜你喜欢
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    • 2017-09-08
    • 2017-09-18
    • 1970-01-01
    相关资源
    最近更新 更多