Ami*_*oSe 9 linux amazon-ec2 amazon-web-services ansible ansible-playbook
我是ansible的新手.我有一个要求,要求我为AWS中托管的450多个Linux服务器提取操作系统版本.AWS不提供此功能 - 它建议我们从木偶或厨师那里获取它.
我创建了几个没有运行的简单剧本
---
- hosts: testmachine
user: ec2-user
sudo: yes
tasks:
- name: Update all packages to latest
yum: name=* state=latest
task:
- name: obtain OS version
shell: Redhat-release
Run Code Online (Sandbox Code Playgroud)
playbook应该输出一个带有主机名和操作系统版本的文本文件.任何有关这方面的见解将受到高度赞赏.
Gab*_*vay 11
使用以下Jinja2表达式之一:
{{ hostvars[inventory_hostname].ansible_distribution }}
{{ hostvars[inventory_hostname].ansible_distribution_major_version }}
{{ hostvars[inventory_hostname].ansible_distribution_version }}
Run Code Online (Sandbox Code Playgroud)
哪里:
hostvars并且ansible_...是内置的,并通过Ansible自动收集ansible_distribution 是Ansible处理的主机例如,假设您test_role对host.example.com运行CentOS 7发行版的主机运行Ansible角色:
---
- debug:
msg: "{{ hostvars[inventory_hostname].ansible_distribution }}"
- debug:
msg: "{{ hostvars[inventory_hostname].ansible_distribution_major_version }}"
- debug:
msg: "{{ hostvars[inventory_hostname].ansible_distribution_version }}"
Run Code Online (Sandbox Code Playgroud)
会给你:
TASK [test_role : debug] *******************************************************
ok: [host.example.com] => {
"msg": "CentOS"
}
TASK [test_role : debug] *******************************************************
ok: [host.example.com] => {
"msg": "7"
}
TASK [test_role : debug] *******************************************************
ok: [host.example.com] => {
"msg": "7.5.1804"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19830 次 |
| 最近记录: |