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

...

相关推荐
码农101号31 分钟前
Linux中shell编程表达式和数组讲解
linux·运维·服务器
程序员的世界你不懂40 分钟前
Appium+python自动化(十)- 元素定位
python·appium·自动化
powerfulzyh44 分钟前
非Root用户启动SSH服务经验小结
运维·ssh
云道轩1 小时前
升级centos 7.9内核到 5.4.x
linux·运维·centos
爱学习的小道长1 小时前
Ubuntu Cursor升级成v1.0
linux·运维·ubuntu
EelBarb1 小时前
seafile:ubuntu搭建社区版seafile12.0
linux·运维·ubuntu
402 Payment Required1 小时前
serv00 ssh登录保活脚本-邮件通知版
运维·chrome·ssh
小柏ぁ2 小时前
calico/node is not ready: BIRD is not ready: BGP not established with xxx
运维·docker·kubernetes
Mintimate2 小时前
云服务器 Linux 手动 DD 安装第三方 Linux 发行版:原理与实战
linux·运维·服务器
RussellFans2 小时前
Linux 环境配置
linux·运维·服务器