RedHat运维-Ansible自动化运维基础27-管理启动进程和计划任务

  1. ansible.posix.at:写一个playbook,让所有的受控主机在20分钟之后,执行命令ls -d / >/dev/null,确保这个任务是独一无二的;

  2. ansible.posix.at:写一个playbook,确保任务ls -d / >/dev/null不存在;

  3. ansible.posix.cron:写一个playbook,对于用户centos,每天的2点和5点都会运行任务ls -alh > /dev/null;

  4. ansible.posix.cron:写一个playbook,对于用户centos,每周五16点每隔两分钟,都会运行任务ls -alh > /dev/null;

  5. ansible.builtin.service:启动并开机自启httpd服务;

  6. ansible.builtin.systemd:启动并开机自启httpd服务;

  7. ansible.builtin.systemd:重新加载所有对于httpd配置的改动,然后重启httpd服务;

  8. ansible.builtin.command:写一个playbook,将默认target设置为multi-user.target;

  9. ansible.builtin.reboot:重启受控主机;

  10. /* A20240605.yaml */


  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.posix.at:

command: ls -d / >/dev/null

count: 20

units: minutes

unique: yes

...

  1. /* B20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.posix.at:

command: ls -d / >/dev/null

state: absent

...

  1. /* C20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.cron:

user: centos

name: job1

job: "ls -alh > /dev/null"

hour: "2,5"

...

  1. /* D20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.cron:

user: centos

name: job2

job: "ls -alh > /dev/null"

weekday: "5"

hour: "16"

minute: "*/2"

...

  1. /* E20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.service:

name: httpd

state: started

enabled: true

...

  1. /* F20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.systemd:

name: httpd

state: started

enabled: true

...

  1. /* G20240605.yaml */

  • name: Play1

hosts: all

tasks:

  • name: Task1

ansible.builtin.systemd:

name: httpd

state: reloaded

daemon_reload: yes

...

  1. /* H20240605.yaml */

  • name: Play1

hosts: all

vars:

  • target: multi-user.target

tasks:

  • name: Task1

ansible.builtin.command:

cmd: systemctl get-default

changed_when: false

register: Task1result

  • name: Task2

ansible.builtin.command:

cmd: systemctl set-default {{ target }}

when: target not in Task1result.stdout

...

  1. /* I20240605.yaml */

  • name: Play1

hosts: centos7.example.com,centos8.example.com

tasks:

  • name: Task1

ansible.builtin.reboot:

reboot_timeout: 180

...

相关推荐
测试员周周2 小时前
【Appium 系列】第16节-WebView-H5上下文切换 — 混合应用的自动化难点
运维·开发语言·人工智能·功能测试·appium·自动化·测试用例
北京耐用通信5 小时前
全域适配工业场景耐达讯自动化Modbus TCP 转 PROFIBUS 网关轻松实现以太网与现场总线互通
网络·人工智能·网络协议·自动化·信息与通信
在角落发呆5 小时前
Linux转发配置:解锁网络互联的核心密码
linux·运维·网络
裴东青7 小时前
10-实战:RuoYi-Cloud的自动化发布
运维·ci/cd·自动化
哎呦,帅小伙哦7 小时前
Linux 时间:从原子钟到 clock_gettime 的每一面
linux·运维·服务器
sxgzzn7 小时前
新能源场站数智化转型:基于数字孪生与AI的智慧运维管理平台解析
大数据·运维·人工智能
张小姐的猫8 小时前
【Linux】多线程 —— 线程互斥
linux·运维·服务器·c++
迁移科技8 小时前
告别人工分拣!迁移科技 AI+3D 视觉让机器人 “看懂” 无序抓取
人工智能·科技·3d·机器人·自动化·视觉检测
CodeMartain8 小时前
Dify Windows 原生部署(无 Docker、纯本地)
运维·docker·容器
xxx1x1x8 小时前
极客向:DLL/运行库故障的底层逻辑与自动化修复方案
运维·自动化·dll文件·dll·dll修复·dll缺失·dll一键修复