中职网络建设与运维ansible服务

ansible服务

填写hosts指定主机范围和控制节点后创建一个脚本,可以利用简化脚本

1. 在linux1上安装系统自带的ansible-core,作为ansible控制节点,linux2-linux7作为ansible的受控节点

Linux1

Linux1-7 Yum install ansible-core -y

Vi /etc/ansible/hosts

添加

复制代码
[linux1]
​
linux1.skills.lan
​
[linux2-linux7]
​
linux2.skills.lan
​
linux3.skills.lan
​
linux4.skills.lan
​
linux5.skills.lan
​
linux6.skills.lan
​
linux7.skills.lan

在linux1编写/root/skills.yul剧本,仅在linux1节点运行,实现如下功能:为主控节点和受控节点同时安装lrzsz软件

复制代码
vim /etc/ansible/ansible.cfg添加忽略验证
[defaults]
host_key_checking = False  

**[root@linux1 ~]#

复制代码
ansible-playbook /root/skills.yml

(2)编写/root/host.yml 剧本,实现在所有linux主机的/root 目录下创建一个host.txt 文件,文件内容为:"ansible脚本测试,主机名为:hostname",hostname为各对应主机的FQDN全名。

复制代码
---
- hosts: all
  tasks:
    - name: 1
      file:
        path: /root/host.txt
        state: touch
​
    - name: 1
      lineinfile:
        path: /root/host.txt
        line: "Hostname is: {{ ansible_fqdn }}"
        create: yes
复制代码
- hosts: server
  gather_facts: no
  tasks:
    - name: touch file
      file: path="/root/ansible.txt" state=touch
- hosts: client
  gather_facts: no
  tasks:
    - name: copy file
      copy: src="/root/ansible.txt" dest="/root/"

2022国赛

5.在linux1 上安装ansible,作为ansible的控制节点。linux2-linux7作 为ansible 的受控节点。在linux1编写/root/skills.yaml剧本,实现在linux1 创建文件/root/ansible.txt,并将该文件复制到所有受控节点的/root目录。

复制代码
- hosts: all
  tasks:
    - name: 123
      copy:
        content: "123"
        dest: /root/ansible.txt

在linux1编写cron.yaml脚本实现linux2-linux7每格一小时定时备份/var/log/message/到data_log下,备份策略为递归

复制代码
- hosts: all
  tasks:
    - name: Ensure directory exists for log
      file:
        path: /data_log
        state: directory
​
    - name: Schedule cron job for log rotation
      cron:
        name: Rotate Log
        minute: "0"
        hour: "*/1"
        day: "*"
        month: "*"
        weekday: "*"
        job: "cat /var/log/messages >> /data_log/message && echo '' > /var/log/messages"

竞赛培训请联系主页!

https://gw.mobei.space

相关推荐
愚公搬代码10 小时前
【愚公系列】《数据可视化分析与实践》015-数据源(本地文件Excel)
信息可视化·excel
开开心心就好1 天前
轻松鼠标连, 自定义区域模仿人手点击
人工智能·windows·物联网·计算机视觉·计算机外设·ocr·excel
AI_56781 天前
ableau可视化进阶:颜色与交互设计让数据会说话
数据库·云原生·excel
城数派1 天前
2001-2024年我国乡镇级的逐年植被净初级生产力(NPP)数据(Shp/Excel格式)
大数据·数据分析·excel
开开心心_Every2 天前
局域网大文件传输,设密码双向共享易用工具
运维·服务器·网络·游戏·pdf·电脑·excel
Data-Miner3 天前
本地化数据分析 agent,让 Excel 数据分析零门槛高效化
数据挖掘·数据分析·excel
盘古工具4 天前
告别重复数据:Excel禁止重复输入的两种方法
windows·excel
jiayong235 天前
Excel 核心功能详解
信息可视化·excel
未来之窗软件服务5 天前
万象EXCEL(二十五)租赁设备管理系统,设备租赁—东方仙盟
大数据·excel·仙盟创梦ide·东方仙盟·万象excel
骑猪撞地球QAQ5 天前
Java在导出excel时中添加图片导出
java·开发语言·excel