shell Ansible:如何使用'yum'命令与'expect'模块?

h6my8fg2  于 2023-05-18  发布在  Shell
关注(0)|答案(1)|浏览(251)

以下是剧本:

- name: Find "N-1" unpatching ID from the Yum History
  become: yes
  shell: yum history | head -n -3 | tail -n +5 | awk '{print $1}' | head -n +1
  register: unpatch
        
- name: Use expect module to unpatch the server to N-1 level
  expect:
    command: yum history undo {{ unpatch.stdout_lines }}
    responses: 
       'Is this ok \[y/d/N]\:"y"'

在第二个任务上运行此Playbook时出现的错误如下:

fatal: [linux-Server-x86-64]: FAILED! => {"changed": false, "msg": "argument responses is of type <type 'str'> and we were unable to convert to dict: dictionary requested, could not parse JSON or key=value"}

我试图对命令yum history undo ${ID}做出各种响应,但它要么在游戏中的任务级别卡住了,要么yum进程一直挂在系统中。

- name: Use expect module to unpatch the server to N-1 level
  expect:
    command: yum history undo {{ unpatch.stdout_lines }}
    responses: yes
rks48beu

rks48beu1#

由于您已经在使用command模块,并且无论如何都希望使用yes来回答yum命令提出的问题,因此根据man yum,您可以使用--assumeyes

-y, --assumeyes
              Assume yes; assume that the answer to any question which would be asked is yes.
              Configuration Option: assumeyes

并且该任务将不需要expect模块。

- name: Unpatch the server to N-1 level
  command: yum --assumeyes history undo {{ unpatch.stdout_lines }}

类似问答

相关问题