RUNDECK调用ANSIBLE执行日常的运维工作

系统平台:CENTOS7

可实现多台机器批量挂载磁盘,避免手工操作的错误

ANSIBLE的PLAYBOOK如下:

---
- hosts: "{{ dsthosts }}"
  remote_user: apps
  become: yes
   
  vars:
    # 执行任务的主机,等待RUNDECK传参,主机变量,定义了变量就要在这里赋值,不然报错
    dsthosts: 192.168.156.71   
    # 磁盘的网络路径
    diskuncs: "10.0.0.1:/testsss"
    # 磁盘本地挂载的目录
    mountdir: "/logsss"
    
  tasks:
  - name: mkdir            | 创建挂载的目录
    file:
      path: "{{ mountdir }}"
      state: directory
      mode: 0777    
      
  - name: mountdisks       | 挂载磁盘
    shell: "mount  {{ diskuncs }} {{ mountdir }}"  

  - name: addtorc.local    | 写入启动命令
    lineinfile:
      dest: "/etc/rc.local"
      state: present
      regexp: 'mount {{ diskuncs }} {{ mountdir }}'
      line: "mount {{ diskuncs }} {{ mountdir }}"
      backup: yes
  
  - name: echo cmd_out      | df -h
    shell: "df -h"
    register: startup_out
    
  - name: echo startup_out  | 打印启动信息
    debug: var=startup_out

 

RUNDECK作业如下:

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='dsthosts' required='true' />
        <option name='diskuncs'>
          <description>diskuncs</description>
        </option>
        <option name='mountdir'>
          <description>mountdir</description>
        </option>
      </options>
    </context>
    <defaultTab>summary</defaultTab>
    <description>mounts</description>
    <executionEnabled>true</executionEnabled>
    <group>runjobs</group>
    <id>ef4f173e-6f8f-4cfb-9495-77a371d7336d</id>
    <loglevel>INFO</loglevel>
    <name>mounts</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <exec>ansible-playbook  /testmountbecome.yml --extra-vars "dsthosts=${option.dsthosts} diskuncs=${option.diskuncs} mountdir=${option.mountdir}" </exec>
      </command>
    </sequence>
    <uuid>ef4f173e-6f8f-4cfb-9495-77a371d7336d</uuid>
  </job>
</joblist>

 

执行效果如图:

 

事实上很多运维的相关工作都可以通过这种方式来完成,比如应用程序包的更新等等,实现的方式都是一样的

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页