我是靠谱客的博主 活泼季节,最近开发中收集的这篇文章主要介绍SaltStack return与job管理,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1. SaltStack组件之return

return组件可以理解为SaltStack系统对执行Minion返回后的数据进行存储或者返回给其他程序,它支持多种存储方式,比如用MySQL、MongoDB、Redis、Memcache等,通过return我们可以对SaltStack的每次操作进行记录,对以后日志审计提供了数据来源。目前官方已经支持30种return数据存储与接口,我们可以很方便的配置与使用它。当然也支持自己定义的return,自定义的return需由python来编写。在选择和配置好要使用的return后,只需在salt命令后面指定return即可。

//实例
[root@master ~]# salt 'node1' sys.list_returners
node1:
    - carbon
    - couchdb
    - etcd
    - highstate
    - local
    - local_cache
    - mattermost
    - multi_returner
    - pushover
    - rawfile_json
    - slack
    - slack_webhook
    - smtp
    - splunk
    - sqlite3
    - syslog
    - telegram

1.1 return流程

return是在Master端触发任务,然后Minion接受处理任务后直接与return存储服务器建立连接,然后把数据return存到存储服务器。关于这点一定要注意,因为此过程都是Minion端操作存储服务器,所以要确保Minion端的配置跟依赖包是正确的,这意味着我们将必须在每个Minion上安装指定的return方式依赖包,假如使用Mysql作为return存储方式,那么我们将在每台Minion上安装python-mysql模块。

1.2 使用mysql作为return存储方式

环境说明:

centos8

主机名IP地址部署功能实现功能
master192.168.143.101salt-mastermaster端 控制端执行效果
node1192.168.143.102salt-minion mariadb python3-PyMySQLminion端 执行命令
node2192.168.143.103mariadb mariadb-serverreturn 数据库存储

在所有minion上安装Mysql-python模块

[root@master salt]# salt-key -L
Accepted Keys:
node1
Denied Keys:
Unaccepted Keys:
master
node2
node3
node4
node5
Rejected Keys:
[root@master salt]# salt '*' test.ping
node1:
    True
[root@node1 ~]# dnf list all|grep -i 'mysql' |grep python
python2-PyMySQL.noarch                                 0.8.0-10.module_el8.4.0+642+1dc4fb01              appstream        
python3-PyMySQL.noarch                                 0.10.1-2.module_el8.4.0+666+456f5f48              appstream        
python38-PyMySQL.noarch                                0.10.1-1.module_el8.4.0+677+b84873a2              appstream        
python39-PyMySQL.noarch                                0.10.1-2.module_el8.4.0+680+7b309a77              appstream        
[root@node1 ~]# dnf -y install python3-PyMySQL 

部署一台mysql服务器用作存储服务器,此处就直接在192.168.143.103这台主机上部署

[root@node2 ~]# dnf -y install mariadb-server mariadb
[root@node2 ~]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@node2 ~]# ss -atnl
State  Recv-Q Send-Q Local Address:Port   Peer Address:Port Process 
LISTEN 0      128          0.0.0.0:22          0.0.0.0:*            
LISTEN 0      80                 *:3306              *:*            
LISTEN 0      128                *:80                *:*            
LISTEN 0      128             [::]:22             [::]:*    

[root@node2 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 8
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> set password = password("qwer123!");
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> quit
Bye
[root@node2 ~]# mysql -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 9
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> quit
Bye
//在node2上面创建数据库和表结构
[root@node2 ~]# mysql -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 10
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE  `salt`
    ->   DEFAULT CHARACTER SET utf8
    ->   DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| salt               |
+--------------------+
4 rows in set (0.003 sec)

MariaDB [(none)]> use salt
Database changed
MariaDB [salt]> DROP TABLE IF EXISTS `jids`;
Query OK, 0 rows affected, 1 warning (0.005 sec)

MariaDB [salt]> CREATE TABLE `jids` (
    ->   `jid` varchar(255) NOT NULL,
    ->   `load` mediumtext NOT NULL,
    ->   UNIQUE KEY `jid` (`jid`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.006 sec)

MariaDB [salt]> show tables;
+----------------+
| Tables_in_salt |
+----------------+
| jids           |
+----------------+
1 row in set (0.000 sec)

MariaDB [salt]> CREATE TABLE `salt_returns` (
    ->   `fun` varchar(50) NOT NULL,
    ->   `jid` varchar(255) NOT NULL,
    ->   `return` mediumtext NOT NULL,
    ->   `id` varchar(255) NOT NULL,
    ->   `success` varchar(10) NOT NULL,
    ->   `full_ret` mediumtext NOT NULL,
    ->   `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    ->   KEY `id` (`id`),
    ->   KEY `jid` (`jid`),
    ->   KEY `fun` (`fun`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.004 sec)

MariaDB [salt]> CREATE TABLE `salt_events` (
    -> `id` BIGINT NOT NULL AUTO_INCREMENT,
    -> `tag` varchar(255) NOT NULL,
    -> `data` mediumtext NOT NULL,
    -> `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    -> `master_id` varchar(255) NOT NULL,
    -> PRIMARY KEY (`id`),
    -> KEY `tag` (`tag`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.007 sec)

MariaDB [salt]> 
//授权访问
MariaDB [salt]> grant all on salt.* to salt@'%' identified by 'salt';
Query OK, 0 rows affected (0.001 sec)

MariaDB [salt]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MariaDB [salt]> quit

配置minion

//node1上测试测试能否连接
[root@node1 ~]# dnf -y install mariadb
[root@node1 ~]# mysql -usalt -psalt -h192.168.143.103
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 11
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> quit
Bye
//配置minion文件
[root@node1 ~]# vim /etc/salt/minion
# Default Minion returners. Can be a comma delimited string or a list: //returners查找关键字
#
#return: mysql
#
#return: mysql,slack,redis
#
#return:
#  - mysql
#  - hipchat
#  - slack  
mysql.host: '192.168.143.103'  //mysql主机ip
mysql.user: 'salt'
mysql.pass: 'salt' //添加五行内容
mysql.db: 'salt'
mysql.port: 3306

在Master上测试存储到mysql中

[root@master salt]# salt '*' test.ping
node1:
    True
[root@master salt]# salt '*' test.ping --return mysql
node1:
    True

在数据库中查询

[root@node2 ~]# mysql -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 12
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> use salt
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [salt]> select * from salt_returnsG
Empty set (0.000 sec)

MariaDB [salt]> select * from salt_returnsG
*************************** 1. row ***************************
       fun: test.ping
       jid: 20211106152012654844 \可查看jid结果
    return: true
        id: node1
   success: 1
  full_ret: {"success": true, "return": true, "retcode": 0, "jid": "20211106152012654844", "fun": "test.ping", "fun_args": [], "id": "node1"}
alter_time: 2021-11-06 11:20:12
1 row in set (0.000 sec)
[root@master salt]# salt-run jobs.lookup_jid 20211106152012654844
node1:
    True

2. job cache

2.1 job cache流程

return时是由Minion直接与存储服务器进行交互,因此需要在每台Minion上安装指定的存储方式的模块,比如python-mysql,那么我们能否直接在Master上就把返回的结果给存储到存储服务器呢?

答案是肯定的,这种方式被称作 job cache 。意思是当Minion将结果返回给Master后,由Master将结果给缓存在本地,然后将缓存的结果给存储到指定的存储服务器,比如存储到mysql中。
环境说明:

centos8

主机名IP地址部署功能实现功能
master192.168.143.101salt-master mariadb python3-PyMySQLmaster端 控制端执行效果
node1192.168.143.102salt-minionminion端 执行命令
node2192.168.143.103mariadb mariadb-serverjob cache 数据库存储

开启master端的master_job_cache

//配置mysql模块文件
[root@master ~]# dnf -y install mariadb
[root@master ~]# mysql -usalt -psalt -h192.168.143.103
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 11
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> quit
Bye

//注意先安装mysql-python模块
[root@master jobs]# dnf list all|grep -i 'mysql' |grep 'python'
python2-PyMySQL.noarch                                 0.8.0-10.module_el8.4.0+642+1dc4fb01              appstream        
python3-PyMySQL.noarch                                 0.10.1-2.module_el8.4.0+666+456f5f48              appstream        
python38-PyMySQL.noarch                                0.10.1-1.module_el8.4.0+677+b84873a2              appstream        
python39-PyMySQL.noarch                                0.10.1-2.module_el8.4.0+680+7b309a77              appstream        
[root@master jobs]# dnf -y install python3-PyMySQL
//配置mater的job_cache
[root@master ~]# vim /etc/salt/master
。。。
#job_cache: True //搜索关键字job_cache
mysql.host: '192.168.143.103'  //mysql主机ip
mysql.user: 'salt'
mysql.pass: 'salt' //添加六行内容
mysql.db: 'salt'
mysql.port: 3306
master_job_cache: mysql
。。。
[root@master ~]# systemctl restart salt-master.service

部署一台mysql服务器用作存储服务器,此处就直接在192.168.143.103这台主机上部署

[root@node2 ~]# dnf -y install mariadb-server mariadb
[root@node2 ~]# systemctl enable --now mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@node2 ~]# ss -atnl
State  Recv-Q Send-Q Local Address:Port   Peer Address:Port Process 
LISTEN 0      128          0.0.0.0:22          0.0.0.0:*            
LISTEN 0      80                 *:3306              *:*            
LISTEN 0      128                *:80                *:*            
LISTEN 0      128             [::]:22             [::]:*    

[root@node2 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 8
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> set password = password("qwer123!");
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> quit
Bye
[root@node2 ~]# mysql -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 9
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> quit
Bye
//在node2上面创建数据库和表结构
[root@node2 ~]# mysql -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 10
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE  `salt`
    ->   DEFAULT CHARACTER SET utf8
    ->   DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| salt               |
+--------------------+
4 rows in set (0.003 sec)

MariaDB [(none)]> use salt
Database changed
MariaDB [salt]> DROP TABLE IF EXISTS `jids`;
Query OK, 0 rows affected, 1 warning (0.005 sec)

MariaDB [salt]> CREATE TABLE `jids` (
    ->   `jid` varchar(255) NOT NULL,
    ->   `load` mediumtext NOT NULL,
    ->   UNIQUE KEY `jid` (`jid`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.006 sec)

MariaDB [salt]> show tables;
+----------------+
| Tables_in_salt |
+----------------+
| jids           |
+----------------+
1 row in set (0.000 sec)

MariaDB [salt]> CREATE TABLE `salt_returns` (
    ->   `fun` varchar(50) NOT NULL,
    ->   `jid` varchar(255) NOT NULL,
    ->   `return` mediumtext NOT NULL,
    ->   `id` varchar(255) NOT NULL,
    ->   `success` varchar(10) NOT NULL,
    ->   `full_ret` mediumtext NOT NULL,
    ->   `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    ->   KEY `id` (`id`),
    ->   KEY `jid` (`jid`),
    ->   KEY `fun` (`fun`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.004 sec)

MariaDB [salt]> CREATE TABLE `salt_events` (
    -> `id` BIGINT NOT NULL AUTO_INCREMENT,
    -> `tag` varchar(255) NOT NULL,
    -> `data` mediumtext NOT NULL,
    -> `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    -> `master_id` varchar(255) NOT NULL,
    -> PRIMARY KEY (`id`),
    -> KEY `tag` (`tag`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.007 sec)

MariaDB [salt]> 
//授权访问
MariaDB [salt]> grant all on salt.* to salt@'%' identified by 'salt';
Query OK, 0 rows affected (0.001 sec)

MariaDB [salt]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MariaDB [salt]> quit

在数据库服务器中清空表内容

[root@node2 ~]# mysql -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 10
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> delete from salt.salt_returns;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> select * from salt.salt_returns;
Empty set (0.000 sec)

在master上再次测试能否存储至数据库

[root@master ~]#  salt '*' cmd.run 'df -h'
node1:
    Filesystem           Size  Used Avail Use% Mounted on
    devtmpfs             876M     0  876M   0% /dev
    tmpfs                896M   60K  896M   1% /dev/shm
    tmpfs                896M  8.7M  887M   1% /run
    tmpfs                896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/cl-root   64G  2.9G   61G   5% /
    /dev/sr0             9.3G  9.3G     0 100% /mnt
    /dev/sda1           1014M  197M  818M  20% /boot
    /dev/mapper/cl-home   32G  255M   31G   1% /home
    tmpfs                180M     0  180M   0% /run/user/0
    
//node2再次查看数据发现已经存储
MariaDB [(none)]> select * from salt.salt_returnsG
*************************** 1. row ***************************
       fun: test.ping
       jid: 20211107063227111550
    return: true
        id: node1
   success: 1
  full_ret: {"cmd": "_return", "id": "node1", "success": true, "return": true, "retcode": 0, "jid": "20211107063227111550", "fun": "test.ping", "fun_args": [], "_stamp": "2021-11-07T06:32:27.338308"}
alter_time: 2021-11-07 01:32:27
1 row in set (0.000 sec)

MariaDB [(none)]> select * from salt.salt_returnsG
*************************** 1. row ***************************
       fun: test.ping
       jid: 20211107063227111550
    return: true
        id: node1
   success: 1
  full_ret: {"cmd": "_return", "id": "node1", "success": true, "return": true, "retcode": 0, "jid": "20211107063227111550", "fun": "test.ping", "fun_args": [], "_stamp": "2021-11-07T06:32:27.338308"}
alter_time: 2021-11-07 01:32:27
*************************** 2. row ***************************
       fun: runner.jobs.lookup_jid
       jid: 20211107063530824465
    return: {"fun": "runner.jobs.lookup_jid", "jid": "20211107063530824465", "user": "root", "fun_args": ["20211107063227111550"], "_stamp": "2021-11-07T06:35:31.530054", "return": {"node1": true}, "success": true}
        id: master_master
   success: 0
  full_ret: {"id": "master_master", "tgt": "master_master", "jid": "20211107063530824465", "return": {"fun": "runner.jobs.lookup_jid", "jid": "20211107063530824465", "user": "root", "fun_args": ["20211107063227111550"], "_stamp": "2021-11-07T06:35:31.530054", "return": {"node1": true}, "success": true}, "fun": "runner.jobs.lookup_jid", "user": "root"}
alter_time: 2021-11-07 01:35:47
*************************** 3. row ***************************
       fun: cmd.run
       jid: 20211107063957998953
    return: "Filesystem           Size  Used Avail Use% Mounted onndevtmpfs             876M     0  876M   0% /devntmpfs                896M   60K  896M   1% /dev/shmntmpfs                896M  8.7M  887M   1% /runntmpfs                896M     0  896M   0% /sys/fs/cgroupn/dev/mapper/cl-root   64G  2.9G   61G   5% /n/dev/sr0             9.3G  9.3G     0 100% /mntn/dev/sda1           1014M  197M  818M  20% /bootn/dev/mapper/cl-home   32G  255M   31G   1% /homentmpfs                180M     0  180M   0% /run/user/0"
        id: node1
   success: 1
  full_ret: {"cmd": "_return", "id": "node1", "success": true, "return": "Filesystem           Size  Used Avail Use% Mounted onndevtmpfs             876M     0  876M   0% /devntmpfs                896M   60K  896M   1% /dev/shmntmpfs                896M  8.7M  887M   1% /runntmpfs                896M     0  896M   0% /sys/fs/cgroupn/dev/mapper/cl-root   64G  2.9G   61G   5% /n/dev/sr0             9.3G  9.3G     0 100% /mntn/dev/sda1           1014M  197M  818M  20% /bootn/dev/mapper/cl-home   32G  255M   31G   1% /homentmpfs                180M     0  180M   0% /run/user/0", "retcode": 0, "jid": "20211107063957998953", "fun": "cmd.run", "fun_args": ["df -h"], "_stamp": "2021-11-07T06:39:58.175936"}
alter_time: 2021-11-07 01:39:58
3 rows in set (0.000 sec)
[root@master ~]# salt-run jobs.lookup_jid 20211107063957998953
node1:
    Filesystem           Size  Used Avail Use% Mounted on
    devtmpfs             876M     0  876M   0% /dev
    tmpfs                896M   60K  896M   1% /dev/shm
    tmpfs                896M  8.7M  887M   1% /run
    tmpfs                896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/cl-root   64G  2.9G   61G   5% /
    /dev/sr0             9.3G  9.3G     0 100% /mnt
    /dev/sda1           1014M  197M  818M  20% /boot
    /dev/mapper/cl-home   32G  255M   31G   1% /home
    tmpfs                180M     0  180M   0% /run/user/0

在数据库中查询

//先测试触发
[root@master ~]# salt '*' test.ping
node1:
    True
//查询数据库是否记录
MariaDB [(none)]> select * from salt.salt_returnsG
*************************** 1. row ***************************
       fun: test.ping
       jid: 20211107063227111550
    return: true
        id: node1
   success: 1
  full_ret: {"cmd": "_return", "id": "node1", "success": true, "return": true, "retcode": 0, "jid": "20211107063227111550", "fun": "test.ping", "fun_args": [], "_stamp": "2021-11-07T06:32:27.338308"}
alter_time: 2021-11-07 01:32:27
1 row in set (0.000 sec)
//数据表中的jobs查看运行的内容
[root@master ~]# salt-run jobs.lookup_jid 20211107063227111550
node1:
    True

2.2 job管理

jobs.active执行过程中查看jobs的信息

[root@node1 ~]# rpm -qa|grep httpd
[root@master ~]# salt '*' pkg.install httpd
执行过程中
[root@master ~]# salt-run jobs.active
20211107064709735121:
    ----------
    Arguments:
        - httpd
    Function:
        pkg.install
    Returned:
    Running:
        |_
          ----------
          node1:
              1781
    StartTime:
        2021, Nov 07 06:47:09.735121
    Target:
        *
    Target-type:
        glob
    User:
        root
[root@master ~]# salt '*' pkg.install httpd
//执行完成或者是错误
[root@master ~]# salt-run jobs.active
//显示空

jobs.list_jobs列出所有的jid

[root@master ~]# salt-run jobs.list_jobs
20211107063227111550:
    ----------
    Arguments:
    Function:
        test.ping
    StartTime:
        2021, Nov 07 06:32:27.111550
    Target:
        *
    Target-type:
        glob
    User:
        root
20211107063530824465:
    ----------
    Arguments:
    Function:
        runner.jobs.lookup_jid
    StartTime:
        2021, Nov 07 06:35:30.824465
    Target:
        master_master
    Target-type:
        list
    User:
        root
20211107063957998953:
    ----------
    Arguments:
        - df -h
    Function:
        cmd.run
    StartTime:
        2021, Nov 07 06:39:57.998953
    Target:
        *
    Target-type:
        glob
    User:
        root
20211107064249736251:
    ----------
    Arguments:
    Function:
        runner.jobs.lookup_jid
    StartTime:
        2021, Nov 07 06:42:49.736251
    Target:
        master_master
    Target-type:
        list
    User:
        root
20211107064418404632:
    ----------
    Arguments:
    Function:
        runner.jobs.active
    StartTime:
        2021, Nov 07 06:44:18.404632
    Target:
        master_master
    Target-type:
        list
    User:
        root
20211107064419142800:
    ----------
    Arguments:
    Function:
        saltutil.running
    StartTime:
        2021, Nov 07 06:44:19.142800
    Target:
        *
    Target-type:
        glob
    User:
        root
20211107064709735121:
    ----------
    Arguments:
        - httpd
    Function:
        pkg.install
    StartTime:
        2021, Nov 07 06:47:09.735121
    Target:
        *
    Target-type:
        glob
    User:
        root
20211107064714840083:
    ----------
    Arguments:
    Function:
        runner.jobs.active
    StartTime:
        2021, Nov 07 06:47:14.840083
    Target:
        master_master
    Target-type:
        list
    User:
        root
20211107064714927092:
    ----------
    Arguments:
        - 20211107064709735121
    Function:
        saltutil.find_job
    StartTime:
        2021, Nov 07 06:47:14.927092
    Target:
        - node1
    Target-type:
        list
    User:
        root
20211107064716552160:
    ----------
    Arguments:
    Function:
        saltutil.running
    StartTime:
        2021, Nov 07 06:47:16.552160
    Target:
        *
    Target-type:
        glob
    User:
        root
20211107064732729071:
    ----------
    Arguments:
    Function:
        runner.jobs.active
    StartTime:
        2021, Nov 07 06:47:32.729071
    Target:
        master_master
    Target-type:
        list
    User:
        root
20211107064733403300:
    ----------
    Arguments:
    Function:
        saltutil.running
    StartTime:
        2021, Nov 07 06:47:33.403300
    Target:
        *
    Target-type:
        glob
    User:
        root
20211107065210668753:
    ----------
    Arguments:
    Function:
        runner.jobs.lookup_jid
    StartTime:
        2021, Nov 07 06:52:10.668753
    Target:
        master_master
    Target-type:
        list
    User:
        root

-v获取任务的jid

[root@master ~]# salt '*' cmd.run 'df -h' -v
Executing job with jid 20211107065531741047
-------------------------------------------

node1:
    Filesystem           Size  Used Avail Use% Mounted on
    devtmpfs             876M     0  876M   0% /dev
    tmpfs                896M   40K  896M   1% /dev/shm
    tmpfs                896M  8.7M  887M   1% /run
    tmpfs                896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/cl-root   64G  3.0G   61G   5% /
    /dev/sr0             9.3G  9.3G     0 100% /mnt
    /dev/sda1           1014M  197M  818M  20% /boot
    /dev/mapper/cl-home   32G  255M   31G   1% /home
    tmpfs                180M     0  180M   0% /run/user/0

jobs.lookup_jid通过jid获取此任务的返回结果

[root@master ~]# salt-run jobs.lookup_jid 20211107064709735121
node1:
    ----------
    apr:
        ----------
        new:
            1.6.3-11.el8
        old:
    apr-util:
        ----------
        new:
            1.6.1-6.el8
        old:
    apr-util-bdb:
        ----------
        new:
            1.6.1-6.el8
        old:
    apr-util-openssl:
        ----------
        new:
            1.6.1-6.el8
        old:
    centos-logos-httpd:
        ----------
        new:
            85.8-1.el8
        old:
    httpd:
        ----------
        new:
            2.4.37-39.module_el8.4.0+950+0577e6ac.1
        old:
    httpd-filesystem:
        ----------
        new:
            2.4.37-39.module_el8.4.0+950+0577e6ac.1
        old:
    httpd-tools:
        ----------
        new:
            2.4.37-39.module_el8.4.0+950+0577e6ac.1
        old:
    mailcap:
        ----------
        new:
            2.1.48-3.el8
        old:
    mod_http2:
        ----------
        new:
            1.15.7-3.module_el8.4.0+778+c970deab
        old:
[root@master ~]# salt-run jobs.lookup_jid 20211107065531741047
node1:
    Filesystem           Size  Used Avail Use% Mounted on
    devtmpfs             876M     0  876M   0% /dev
    tmpfs                896M   40K  896M   1% /dev/shm
    tmpfs                896M  8.7M  887M   1% /run
    tmpfs                896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/cl-root   64G  3.0G   61G   5% /
    /dev/sr0             9.3G  9.3G     0 100% /mnt
    /dev/sda1           1014M  197M  818M  20% /boot
    /dev/mapper/cl-home   32G  255M   31G   1% /home
    tmpfs                180M     0  180M   0% /run/user/0

最后

以上就是活泼季节为你收集整理的SaltStack return与job管理的全部内容,希望文章能够帮你解决SaltStack return与job管理所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(35)

评论列表共有 0 条评论

立即
投稿
返回
顶部