一.主机信息提取
1.创建hostinfo.yml文件
[devops@server4 ansible]$ vim hostinfo.yml
---
- hosts: all
tasks:
- name: create infofile
template:
src: templates/info.j2
dest: /mnt/hostinfo
2.在templates创建模版info.j2
[devops@server4 ansible]$ cd templates/
[devops@server4 templates]$ vim info.j2
主机名: {
{ ansible_facts['hostname'] }}
根分区大小: {
{ ansible_facts['devices']['dm-0']['size'] }}
系统内核: {
{ ansible_facts['kernel'] }}
系统版本: {
{ ansible_facts['distribution_version'] }}
DNS: {
{ ansible_facts['dns']['nameservers'] }}
3.语法检测
[devops@server4 ansible]$ ansible-playbook hostinfo.yml --syntax-check
playbook: hostinfo.yml
4.推送
[devops@server4 ansible]$ ansible-playbook hostinfo.yml

本文介绍了使用Ansible Playbook进行一键化部署的实践过程,包括主机信息提取、服务安装、通过变量推送解析文件以及用户管理。在主机信息提取中,详细阐述了创建模板文件、语法检测和推送的步骤。服务安装部分讲解了如何为多台主机安装服务。通过变量的方式推送解析文件,强调了模板目录的使用和变量的配置。用户管理章节涵盖了用户创建、用户信息安全管理,特别是对密码加密的处理。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



