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

...

相关推荐
wanhengidc1 小时前
云手机 高振畅玩不踩坑
运维·服务器·安全·web安全·智能手机
有谁看见我的剑了?1 小时前
linux 添加硬盘后系统识别不到硬盘处理
linux·运维·服务器
JoyCong19981 小时前
ToDesk远程屏幕墙技术白皮书:如何重塑全局运维视界
运维·电脑·远程工作
大势智慧2 小时前
矿影智测版|矿山自动化测绘,省时精准更省心!
自动化·三维建模·智慧矿山·安全巡检·空间智能··露天矿山
偶尔上线经常挺尸2 小时前
《100个“反常识”经验15:Nginx 502排查:从应用到内核》
运维·nginx·性能调优·反向代理·502错误·http排错
思茂信息2 小时前
CST软件如何进行参数化扫描?
运维·开发语言·javascript·windows·ecmascript·软件工程·软件需求
计算机安禾3 小时前
【Linux从入门到精通】第31篇:防火墙漫谈——iptables与firewalld防护指南
linux·运维·php
下一页盛夏花开3 小时前
ubuntu 20中安装QT以后出现红色空心断点
linux·运维·ubuntu
sxgzzn6 小时前
光伏数智化综合平台:让光伏电站运维更智能、更高效
运维