ansible的控制语句

news2024/10/1 17:19:27

本章内容主要介绍 playbook 中的控制语句

  • 使用when判断语句
  • block-rescue判断
  • 循环语句
        一个play中可以包含多个task,如果不想所有的task全部执行,可以设置只有满足某个条件才执行这个task,不满足条件则不执行此task。本章主要讲解when 和 block-rescue两种判断语句。

1.when判断语句

when作为一个判断语句,出现在某个 task下,格式如下。
1 tasks :
2 name : aa
3 模块 1
4 when : 条件 1
如果条件1成立,则执行模块1,否则不执行。

注意: 在when中引用变量时是不用加{{}}的。

        本章实验都在/home/duan/demo3下操作,先把 demo3目录创建出来并把ansible.cfg 和 hosts拷贝进去,命令如下。

[blab@node01 ~]$ mkdir demo3
[blab@node01 ~]$ cp ansible.cfg hosts demo3/
[blab@node01 ~]$ cd demo3
[blab@node01 demo3]$

1.1when判断中>,<,!= 的使用

练习1:写一个playbook,判断某条件是否成立,成立了才执行task,否则不执行,命令如下。
[blab@node01 demo3]$ cat when1.yml 
---
- hosts: node02
  tasks:
  - name: task1
    debug: msg="111"
    when: 1 < 2
[blab@node01 demo3]$ 

        这里有一个task,判断1<2是否成立,如果成立则执行task1,屏幕上会显示111;如果不成立则不执行taskl,屏幕上不会显示111。这里明显是成立的,所以会执行task1。运行结果如下。

[blab@node01 demo3]$ ansible-playbook when1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task1] *******************************************************************
ok: [node02] => {
    "msg": "111"
}

PLAY RECAP *********************************************************************
node02                     : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[blab@node01 demo3]$
        when后面可以有多个条件,用or或and作为连接符。
如果用or作为连接符,只要有一个条件成立即可,只有所有的条件都不成立时,整体才不成立

练习2:修改when1.yml的内容如下。
[blab@node01 demo3]$ cat when1.yml 
---
- hosts: node02
  tasks:
  - name: task1
    debug: msg="111"
    when: 1 < 2 or 2>3
[blab@node01 demo3]$ 
        此处用or作为连接符,只要有一个条件成立就会成立,2>3不成立,但是1<2成立,所以整体上就是成立的。运行结果如下。

[blab@node01 demo3]$ ansible-playbook when1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task1] *******************************************************************
ok: [node02] => {
    "msg": "111"
}

PLAY RECAP *********************************************************************
node02                     : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[blab@node01 demo3]$
仍然会执行task1。

练习3:修改when1.yml的内容如下。
[blab@node01 demo3]$ cat when1.yml 
---
- hosts: node02
  tasks:
  - name: task1
    debug: msg="111"
    when: 1>2 or 2>3
[blab@node01 demo3]$
        此处用or作为连接符,1>2不成立且2>3也不成立,所以整体上就是不成立的,不会执行 task1。运行结果如下。

[blab@node01 demo3]$ ansible-playbook when1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task1] *******************************************************************
skipping: [node02]

PLAY RECAP *********************************************************************
node02                     : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

[blab@node01 demo3]$
        也可以用and作为连接符,如果用and作为连接符,需要所有条件全部成立,只要有一个条件不成立,整体上就是不成立的。

练习4:修改when1.yml的内容如下。
[blab@node01 demo3]$ cat when1.yml 
---
- hosts: node02
  tasks:
  - name: task1
    debug: msg="111"
    when: 2>1 and 2>3
[blab@node01 demo3]$ 
        这里虽然2>1是成立的,但是2>3不成立,所以整体上就是不成立的,因为用and作为连接符,需要所有的条件都成立才可以,所以不会执行task1。运行结果如下。

[blab@node01 demo3]$ ansible-playbook when1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task1] *******************************************************************
skipping: [node02]

PLAY RECAP *********************************************************************
node02                     : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

[blab@node01 demo3]$
在判断中,or 和 and是可以混用的,为了看得更清晰,可以使用小括号。
练习5:修改 when1.yml 的内容如下。
[blab@node01 demo3]$ cat when1.yml 
---
- hosts: node02
  tasks:
  - name: task1
    debug: msg="111"
    when: (1>2 or 2!=1) and 2>3
[blab@node01 demo3]$
        这里(1>2 or 2!=1)作为一个整体,1>2不成立,但是2!=1(=是不等于的意思)成立,所以此处( 1>2 or 2!=1)作为一个整体是成立的。and后面2>3不成立,所以整个when后面的判断是不成立的,不会执行此 task1。运行结果如下。
[blab@node01 demo3]$ ansible-playbook when1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task1] *******************************************************************
skipping: [node02]

PLAY RECAP *********************************************************************
node02                     : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

[blab@node01 demo3]$

常见的判断符包括以下6种:

  1. ==:等于
  2. !=:不等于
  3. >:大于
  4. >=:大于等于
  5. <:小于
  6. <=:小于等于
练习6:如果node02的系统主版本是7(RHEL/CentOS7),则打印111,否则不打印。playbook的内容如下。
[blab@node01 demo3]$ cat when2.yml 
---
- hosts: node02
  tasks:
  - name: task2
    debug: msg="222"
    when: ansible_distribution_major_version == "7"
[blab@node01 demo3]$
因为node02的系统是RHEL8,所以不会执行此task2,即不会显示222。
[blab@node01 demo3]$ ansible-playbook when2.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task2] *******************************************************************
skipping: [node02]

PLAY RECAP *********************************************************************
node02                     : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

[blab@node01 demo3]$ 

注意: ansible_distribution major version的值是一个字符串,所以when判断中=后面的7是要加引号的。
练习7:修改when2.yml 的内容如下。
[blab@node01 demo3]$ cat when2.yml 
---
- hosts: node02
  tasks:
  - name: task2
    debug: msg="222"
    when: ansible_distribution_major_version == "8"
[blab@node01 demo3]$ 
再次运行此playbook,命令如下,会显示222。
[blab@node01 demo3]$ ansible-playbook when2.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task2] *******************************************************************
ok: [node02] => {
    "msg": "222"
}

PLAY RECAP *********************************************************************
node02                     : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[blab@node01 demo3]$
再次提醒:在when 中引用变量时是不用加{{}}的。

1.2 when判断中in的用法

在when语句中,除可以使用上面的大于、小于等判断方法外,还可以使用 in,用法如下。
value in 列表
如果此值在这个列表中,则判断成立,否则不成立。
练习:判断某值是否在列表中,编写 when3.yaml,命令如下。
[blab@node01 demo3]$ cat when3.yml 
--- 
- hosts: node02
  vars:
   list1: [1,2,3,4]
  tasks:
  - name: task3
    debug: msg="333"
    when: 2 in list1
[blab@node01 demo3]$
        此处定义了一个列表 list1,里面有4个值,分别为1、2、3、4;定义了一个task打印333,会不会执行这个task,就要看when后面的判断是否成立。如果2在列表list1中,则执行;如果不在,则不执行,很明显2在列表list1中,所以会执行此task,即屏幕上会显示333。运行结果如下。
[blab@node01 demo3]$ ansible-playbook when3.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task3] *******************************************************************
ok: [node02] => {
    "msg": "333"
}

PLAY RECAP *********************************************************************
node02                     : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[blab@node01 demo3]$
        因为2在列表list1中,when判断成立,可以正确执行task3,所以屏幕上会显示333。修改when-3.yaml的内容如下。
[blab@node01 demo3]$ cat when3.yml 
--- 
- hosts: node02
  vars:
   list1: [1,2,3,4]
  tasks:
  - name: task3
    debug: msg="333"
    when: 2 not  in list1        //增加not
[blab@node01 demo3]$
这里判断的是2不在列表list1中,但2是在列表list1中的,所以判断不成立。运行结果如下。
[blab@node01 demo3]$ ansible-playbook when3.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task3] *******************************************************************
skipping: [node02]

PLAY RECAP *********************************************************************
node02                     : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

[blab@node01 demo3]$
因为when判断不成立,所以屏幕上不会显示333。回想前面的例子。
 ‐‐‐
 ‐ hosts: db
   tasks:
   ‐ name: 打印我在清单文件中的名称
     debug: msg={{inventory_hostname}}
     when: inventory_hostname in groups ['xx']
这里判断当前正在执行的主机是不是属于主机组xx,如果是则执行debug,如果不是则不执行。

1.3 when判断中is的用法

is可以用于判断变量是否被定义,常见的判断包括以下3种:

  1. is defined:变量被定义
  2. is undefined:等同于is not definend,变量没有被定义
  3. is none:变量被定义了,但是值为空
看下面的例子:
[blab@node01 demo3]$ cat when4.yml 
---
- hosts: node02
  vars:
   aa: 1
   bb: 
  tasks:
  - name: task1
    debug: msg="111"
    when: aa is undefined
  - name: task2
    debug: msg="222"
    when: bb is undefined
  - name: task3
    debug: msg="333"
    when: cc is not defined
[blab@node01 demo3]$
首先定义了两个变量:aa和 bb,其中bb的值为空,此处并没有定义cc。后面定义了以下3个task。
(1)如果aa被定义了,则显示111,这里aa被定义了,所以判断成立,会执行task1。
(2)如果b没有被定义,则显示222,这里bb被定义了,所以判断不成立,不会执行task2。
(3)如果cc没有被定义,则显示333,这里cc没有被定义,所以判断成立,会执行task3。
这里is undefined 和is not defined是一个意思。
查看运行的结果,如下所示。
[blab@node01 demo3]$ ansible-playbook when4.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task1] *******************************************************************
skipping: [node02]

TASK [task2] *******************************************************************
skipping: [node02]

TASK [task3] *******************************************************************
ok: [node02] => {
    "msg": "333"
}

PLAY RECAP *********************************************************************
node02                     : ok=2    changed=0    unreachable=0    failed=0    skipped=2    rescued=0    ignored=0   

[blab@node01 demo3]$
练习:写一个playbook,内容如下
[blab@node01 demo3]$ cat when5.yml 
---
- hosts: node02
  tasks:
  - name: 执行一个系统命令
    shell: "ls /aa.txt"
    register: aa
    ignore_errors: yes
  - name: task2
    fail:  msg="命令执行错了001"
    when: aa.rc != 0
  - name: task3
    debug: msg="OK001"

    
[blab@node01 demo3]$
运行此playbook命令如下
[blab@node01 demo3]$ ansible-playbook when5.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [执行一个系统命令] ****************************************************************
fatal: [node02]: FAILED! => {"changed": true, "cmd": "ls /aa.txt", "delta": "0:00:00.004728", "end": "2023-12-22 10:18:56.684797", "msg": "non-zero return code", "rc": 2, "start": "2023-12-22 10:18:56.680069", "stderr": "ls: 无法访问'/aa.txt': 没有那个文件或目录", "stderr_lines": ["ls: 无法访问'/aa.txt': 没有那个文件或目录"], "stdout": "", "stdout_lines": []}
...ignoring

TASK [task2] *******************************************************************
fatal: [node02]: FAILED! => {"changed": false, "msg": "命令执行错了001"}

PLAY RECAP *********************************************************************
node02                     : ok=2    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=1   

[blab@node01 demo3]$

2.判断语句block-rescue

        对于when来说,只能做一个判断,成立就执行,不成立就不执行。block和rescue一般同用,类似于shell判断语句中的if-else,在block下面可以包含多个模块,来判断这多个模块是否执行成功了。
block-rescue的用法如下。
1 block :
2     模块 1
3     模块 2
4     模块 3
5 rescue :
6     模块 1
7     模块 2
        先执行 block中的模块1,如果没有报错,则继续执行模块2,如果block中的所有模块都执行成功了,则跳过rescue 中的所有模块,直接执行下一个task中的模块,如图32-1所示
        这里有2个task : task1和 task2,在 task1的block中有3个模块,rescue中有2个模块。如果 block1中的所有模块都正确执行了,则不执行rescue中的模块,直接执行task2。
        如果 block中的任一模块执行失败,block中其他后续的模块都不再执行,然后会跳转执行 rescue 中的模块,如图32-2所示。
        这里block1中的模块1执行完成之后会执行模块2,如果模块2报错,则不会执行模块3,直接跳转到rescue中,执行模块x。rescue中的所有模块全部正确执行完成之后,则执行task2。
如果rescue中的某个模块执行失败,则退出整个playbook,如图32-3所示。
        这里 block中的模块2执行失败,则跳转到rescue中执行模块x,如果模块x执行失败,则退出整个 playbook,即也不会执行task2了。
        如果某个报错模块有 ignore_errors: yes选项,则会忽略此模块的错误,继续执行下一个模块,如图32-4所示。
        这里block中的模块2执行失败了,但是因为加了ignore_errors: yes选项,所以会忽略这个报错模块,继续执行模块3。
练习1:按上面的描述写一个playbook,内容如下。
[blab@node01 demo3]$ cat block1.yml 
---
- hosts: node02
  tasks:
  - name: task1
    block:
    - name: 11
      debug: msg="111"

    - name: 22
      shell: "ls /aa.txt"

    - name: 33
      debug: msg="333"

    rescue:
    - name: xx
      debug: msg="xxxx"

    - name: yy
      debug: msg="yyy"

    - name: task2
      debug: msg="zzz"

[blab@node01 demo3]$
        这里在task1的block中运行了3个模块,第一个模块可以正确执行,第二个模块是执行一个系统命令ls /aa.txt,但是在server2中是不存在/aa.txt这个文件的,所以这个模块会执行失败。block中的第三个模块不再执行,直接跳转到rescue中的模块。rescue中的2个模块均可正确执行,然后执行task2。
所以,屏幕上会显示1111, xxxx, yyyy, zzzz。运行结果如下。
[blab@node01 demo3]$ ansible-playbook block1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [debug] *******************************************************************
ok: [node02] => {
    "msg": "111"
}

TASK [shell] *******************************************************************
fatal: [node02]: FAILED! => {"changed": true, "cmd": "ls /aa.txt", "delta": "0:00:00.006491", "end": "2023-12-22 10:51:59.038337", "msg": "non-zero return code", "rc": 2, "start": "2023-12-22 10:51:59.031846", "stderr": "ls: 无法访问'/aa.txt': 没有那个文件或目录", "stderr_lines": ["ls: 无法访问'/aa.txt': 没有那个文件或目录"], "stdout": "", "stdout_lines": []}

TASK [xx] **********************************************************************
ok: [node02] => {
    "msg": "xxxx"
}

TASK [yy] **********************************************************************
ok: [node02] => {
    "msg": "yyy"
}

TASK [task2] *******************************************************************
ok: [node02] => {
    "msg": "zzz"
}

PLAY RECAP *********************************************************************
node02                     : ok=5    changed=0    unreachable=0    failed=0    skipped=0    rescued=1    ignored=0   

[blab@node01 demo3]$
练习2: 修改block1.yml的内容如下。
[blab@node01 demo3]$ cat block1.yml 
---
- hosts: node02
  tasks:
  - name: task1
    block:
    - name: 11
      debug: msg="111"

    - name: 22
      shell: "ls /aa.txt"
      ignore_errors: yes        //增加内容

    - name: 33
      debug: msg="333"

    rescue:
    - name: xx
      debug: msg="xxxx"

    - name: yy
      debug: msg="yyy"

    - name: task2
      debug: msg="zzz"

[blab@node01 demo3]$
        与上面的例子相比,在 block的第二个模块中增加了一个 ignore_errors: yes选项,这样block中的第二个模块即使报错了,也会忽略这个报错继续执行第三个模块。然后执行task2,所以屏幕上会显示1111,3333,zzzz。运行结果如下。
[blab@node01 demo3]$ ansible-playbook block1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [debug] *******************************************************************
ok: [node02] => {
    "msg": "111"
}

TASK [shell] *******************************************************************
fatal: [node02]: FAILED! => {"changed": true, "cmd": "ls /aa.txt", "delta": "0:00:00.003277", "end": "2023-12-22 10:55:41.477248", "msg": "non-zero return code", "rc": 2, "start": "2023-12-22 10:55:41.473971", "stderr": "ls: 无法访问'/aa.txt': 没有那个文件或目录", "stderr_lines": ["ls: 无法访问'/aa.txt': 没有那个文件或目录"], "stdout": "", "stdout_lines": []}
...ignoring

TASK [debug] *******************************************************************
ok: [node02] => {
    "msg": "333"
}

PLAY RECAP *********************************************************************
node02                     : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1   

[blab@node01 demo3]$ 

3.循环语句

在shell中 for循环的用法如下。
1 for i in A B C ... ; do
2 命令 $
3 done
        这里首先把A赋值给i,执行do和done之间的命令;然后把B赋值给i,执行do和 done之间的命令,以此类推,直到把in后面所有的值执行完毕。for后面的变量可以随便命名。
再回顾一下前面介绍的列表,如下所示。
employee:
 ‐ uname: lisi
   age: 22
   sex: man

 ‐ uname: wangwu
   age: 24
   sex: man

 ‐ uname: xiaohua
   age: 21
        这里列表employee中有3个元素,分别记录了lisi、wangwu、xiaohua的信息。我们把这3个元素当成刚讲的for循环中的A、B、C。先把第一个元素赋值给变量,执行某个操作,完成之后再把第二个元素赋值给变量。
        用for循环A、B、C,在playbook中用loop来循环列表中的元素。在for循环中,指定一个变量如i,然后分别把A、B、C赋值给i。
        在loop中,使用一个固定的变量 item,然后把每个元素赋值给item,如图32-5所示。第二次循环,如图32-6所示。
练习1:定义一个列表users,然后循环这个列表中的每个元素,命令如下。
[blab@node01 demo3]$ cat loop1.yml 
---
- hosts: node02
  vars:
   users:
    - uname: tom
      age: 20
      sex: man
    
    - uname: bob
      age: 22
      sex: man

    - uname: mary
      age: 19
      sex: woman

  tasks:
  - name: task1
    debug: msg={{item}}
    loop: "{{users}}"
[blab@node01 demo3]$
        这里定义了一个列表users,里面包含了3个用户的信息,在taskl中用loop开始循环这个列表。loop后面写列表名时,需要使用引号引起来,这里的关键字loop可以换成关键字 with_items
        这里首先把users的第一个元素赋值给item,用debug 打印;然后把users的第二个元素赋值给item,用 debug打印,直到把所有的元素都赋值给 item。
运行此 playbook,命令如下。
[blab@node01 demo3]$ ansible-playbook loop1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task1] *******************************************************************
ok: [node02] => (item={'uname': 'tom', 'age': 20, 'sex': 'man'}) => {
    "msg": {
        "age": 20,
        "sex": "man",
        "uname": "tom"
    }
}
ok: [node02] => (item={'uname': 'bob', 'age': 22, 'sex': 'man'}) => {
    "msg": {
        "age": 22,
        "sex": "man",
        "uname": "bob"
    }
}
ok: [node02] => (item={'uname': 'mary', 'age': 19, 'sex': 'woman'}) => {
    "msg": {
        "age": 19,
        "sex": "woman",
        "uname": "mary"
    }
}

PLAY RECAP *********************************************************************
node02                     : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[blab@node01 demo3]$
如果不想打印每个元素的所有条目,只想打印每个元素的uname呢?答案:可以通过练习2 解决
练习2:修改loop1.yml的内容如下。
[blab@node01 demo3]$ cat loop1.yml 
---
- hosts: node02
  vars:
   users:
    - uname: tom
      age: 20
      sex: man
    
    - uname: bob
      age: 22
      sex: man

    - uname: mary
      age: 19
      sex: woman

  tasks:
  - name: task1
    debug: msg={{item.uname}}        //增加内容
    loop: "{{users}}"
[blab@node01 demo3]$ 
        列表的每个元素都是一个字典,所以 item就是字典,要获取这个字典中的uname变量,用 item.uname即可。
运行此 playbook
[blab@node01 demo3]$ ansible-playbook loop1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task1] *******************************************************************
ok: [node02] => (item={'uname': 'tom', 'age': 20, 'sex': 'man'}) => {
    "msg": "tom"
}
ok: [node02] => (item={'uname': 'bob', 'age': 22, 'sex': 'man'}) => {
    "msg": "bob"
}
ok: [node02] => (item={'uname': 'mary', 'age': 19, 'sex': 'woman'}) => {
    "msg": "mary"
}

PLAY RECAP *********************************************************************
node02                     : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[blab@node01 demo3]$
练习3:如果想打印所有性别为男的那些用户名,修改loop1.yml 。
[blab@node01 demo3]$ cat loop1.yml 
---
- hosts: node02
  vars:
   users:
    - uname: tom
      age: 20
      sex: man
    
    - uname: bob
      age: 22
      sex: man

    - uname: mary
      age: 19
      sex: woman

  tasks:
  - name: task1
    debug: msg={{item.uname}}
    when: item.sex == "man"        //增加条件
    loop: "{{users}}"
[blab@node01 demo3]$
        在此playbook中,我们用when加了一个判断。循环列表时,首先把第一个元素赋值给item,然后判断item.sex的值是否为man,如果是则判断成立,执行debug模块;如果不是则判断不成立,不执行debug模块。
        第一次循环结束之后,开始第二次循环,把第二个元素赋值给item之后,做相同的判断。运行此 playbook,命令如下。
[blab@node01 demo3]$ ansible-playbook loop1.yml 

PLAY [node02] ******************************************************************

TASK [Gathering Facts] *********************************************************
ok: [node02]

TASK [task1] *******************************************************************
ok: [node02] => (item={'uname': 'tom', 'age': 20, 'sex': 'man'}) => {
    "msg": "tom"
}
ok: [node02] => (item={'uname': 'bob', 'age': 22, 'sex': 'man'}) => {
    "msg": "bob"
}
skipping: [node02] => (item={'uname': 'mary', 'age': 19, 'sex': 'woman'}) 

PLAY RECAP *********************************************************************
node02                     : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[blab@node01 demo3]$
这样就把所有性别为男的用户名打印出来了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1332812.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Linux安装及管理程序

一、Linux应用程序管理 1、应用程序与系统命令的关系 1.对比系统命令和应用程序的不同 位置&#xff1a; Linux中一切皆为文件 演示内部命令和外部命令 位置 应用程序位置 用途&#xff1a; 命令主要处理系统的基本操作&#xff08;复制&#xff0c;配置&#xff09; 应用程…

大模型工具_Langchain-Chatchat

https://github.com/chatchat-space/Langchain-Chatchat 原Langchain-ChatGLM 1 功能 整体功能&#xff0c;想解决什么问题 基于 Langchain 与 ChatGLM 等LLM模型&#xff0c;搭建一套针对中文场景与开源模型&#xff0c;界面友好、可离线运行的知识库问答解决方案。 当前解决…

米勒电容与米勒效应

米勒电容与米勒效应 米勒效应米勒效应的形成原理及分析米勒效应的危害和改进 米勒效应 Ciss CGE CGC 输入电容 Coss CGC CEC 输出电容 Crss CGC 米勒电容 下面我们以MOS中的米勒效应来展开说明&#xff1a; 米勒效应在MOS驱动中臭名昭著&#xff0c;它是由MOS管的米勒电容引发…

运行时和编译时使用的so库不同是否影响可执行文件执行

引子 近日遇到如下问题: 1.如果可执行文件依赖的so库在编译和执行阶段使用的名字一样&#xff0c;但是内容不一样&#xff0c;比如运行时相比于编译时在so库里增加了几个api定义&#xff0c;so库还可以正常使用吗&#xff1f; 2.如果可执行文件依赖的so库在编译和执行阶段使用的…

buuctf-Misc 题目解答分解94-96

94.[SUCTF 2019]Game 在源码包里面 有一个静态页面和一些样式表 在index,html 中看到了flag base32 解码 得到flag suctf{hAHaha_Fak3_F1ag} 但是显示不对 还有一张图片 进行数据提取发现base64 U2FsdGVkX1zHjSBeYPtWQVSwXzcVFZLu6Qm0To/KeuHg8vKAxFrVQ 解密后发现是Sal…

编译原理--词法分析C++

一、实验项目要求 1.实验目的 通过设计编制调试一个具体的词法分析程序&#xff0c;加深对词法分析原理的理解。并掌握在对程序设计语言源程序进行扫描过程中将其分解为各类单词的词法分析方法。 编制一个读单词过程&#xff0c;从输入的源程序中&#xff0c;识别出各个具有…

XUbuntu22.04之跨平台容器格式工具:MKVToolNix(二百零三)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 优质专栏&#xff1a;多媒…

29.Java程序设计-基于Springboot的幼儿园管理系统的设计与实现

1. 引言 背景介绍&#xff1a;幼儿园管理系统的必要性和重要性。研究目的&#xff1a;设计一个基于Spring Boot的系统以优化幼儿园管理流程。论文结构概览。 2. 需求分析 用户需求&#xff1a;不同用户&#xff08;管理员、老师、家长&#xff09;的需求分析。功能需求&…

多次触发FastJson漏洞的AutoType机制,你了解吗?

一个反序列化问题 在一次日志巡检过程中&#xff0c;发现线上业务出现报错。线上业务场景是&#xff1a;调用三方restful接口&#xff0c;根据接口返回json字符串内容&#xff0c;进行反序列化处理&#xff0c;业务中使用的json处理工具是FastJson(v1.2.71)。 报错是使用fast…

【Linux系统编程二十三】:(信号2)--信号的保存

【Linux系统编程二十三】&#xff1a;信号的保存 一.信号的保存1.阻塞信号2.sigset_t类型(位图)3.block表4.handler表5.pending表 二.实验验证三.信号的其他概念 一.信号的保存 信号发送本质上是操作系统发送信号&#xff0c;而进程PCB内部有一个位图用来表示是否接收到信号。…

T-Dongle-S3开发笔记——创建工程

创建Hello world工程 打开命令面板 方法1&#xff1a;查看->命令面板 方法2&#xff1a;按F1 选择ESP-IDF:展示示例项目 创建helloworld 选择串口 选择芯片 至此可以编译下载运行了 运行后打印的信息显示flash只有2M。但是板子上电flash是W25Q32 4MB的吗 16M-bit

高级RGA(二):父文档检索器

在我之前写的<<使用langchain与你自己的数据对话>>系列博客中&#xff0c;我们介绍了利用大型语言模型LLM来检索文档时的过程和步骤&#xff0c;如下图所示&#xff1a; 我们在检索文档之前&#xff0c;通常需要对文档进行切割&#xff0c;然后将其存入向量数据库如…

用友时空KSOA UploadImage任意文件上传漏洞

漏洞描述 用友时空 KSOA 是根据流通企业前沿的IT需求推出的统的IT基础架构&#xff0c;它可以让流通企业各个时期建立的 IT 系统之间彼此轻松对话。由于用友时空设备开放了文件上传功能&#xff0c;但未鉴权且上传的文件类型、大小、格式、路径等方面进行严格的限制和过滤&…

企业知识库在跨地域团队协作中的价值

随着全球化进程的不断加速&#xff0c;越来越多的企业开始面临跨地域协作的挑战。在这种背景下&#xff0c;企业知识库作为一种重要的知识管理工具&#xff0c;对于提高团队协作效率、促进知识共享与创新具有不可替代的价值。接下来就说一下知识库在跨地域团队协作中的重要性及…

JVM简单学习

jvm与字节码 jvm只需关注字节码文件 jvm由哪些部分构成 1.类加载子系统&#xff0c;将磁盘中的字节码文件加载到方法区的内存空间中 类加载器分两种&#xff1a;引导类加载器是jvm底层中用C和C语言写的 各个默认的类加载器的不同区别在于 各自默认负责要加载的类的目录不一…

web前端游戏项目-辨色大比拼【附源码】

web前端游戏项目-辨色大比拼【附源码】 《辨色大比拼》是一个旨在测试和提升玩家颜色识别能力的在线游戏。在游戏中&#xff0c;玩家将通过辨识颜色来解谜并推进游戏进程。辨色大比拼也是一个寓教于乐的游戏&#xff0c;它不仅提供了一个有趣的辨色挑战&#xff0c;还能帮助玩…

通过 Higress Wasm 插件 3 倍性能实现 Spring-cloud-gateway 功能

作者&#xff1a;韦鑫&#xff0c;Higress Committer&#xff0c;来自南京航空航天大学分布式系统实验室 导读&#xff1a;本文将和大家一同回顾 Spring Cloud Gateway 是如何满足 HTTP 请求/响应转换需求场景的&#xff0c;并为大家介绍在这种场景下使用 Higress 云原生网关的…

【Linux】Linux常见指令解析上

目录 1. 前言2. ls指令3. pwd指令4. cd指令3.1 cd常见快捷指令 4. touch指令5. mkdir指令6. rmdir指令 && rm指令 &#xff08;重要&#xff09;6.1 rmdir指令6.2 rm指令 7. man指令 1. 前言 这篇文章我们将详细介绍一下Linux下常见的基本指令。 2. ls指令 语法: ls [选…

掌握函数式组件:迈向现代化前端开发的关键步骤(上)

&#x1f90d; 前端开发工程师&#xff08;主业&#xff09;、技术博主&#xff08;副业&#xff09;、已过CET6 &#x1f368; 阿珊和她的猫_CSDN个人主页 &#x1f560; 牛客高级专题作者、在牛客打造高质量专栏《前端面试必备》 &#x1f35a; 蓝桥云课签约作者、已在蓝桥云…

精通推荐算法1:为什么需要推荐系统(系列文章,建议收藏)

作者简介&#xff1a; 腾讯算法研究员。硕士毕业于中国科学院大学。在阿里和腾讯工作多年&#xff0c;拥有丰富的搜索和推荐算法经验。CSDN博客专家&#xff0c;原创文章100篇。发表专利15个&#xff0c;其中已授权6个。 1 概述 随着互联网的大力发展&#xff0c;用户规模和…