我如何同意安装软件包?

How do I agree to install the package?

我的剧本:

    - name: "install software"
      hosts: local
      connection: local
    
      tasks:
        - name: install git
          expect:
            command: yum install git
            responses:
              Is this ok [y/d/N]: 'y'

我执行命令sudo ansible-playbook test.yaml,但出现错误。

Total download size: 4.5 M                                                                               
Installed size: 22 M                            
Is this ok [y/d/N]:   

留言:

non-zero return code

一种方法是完全避免使用 expect 模块,而是使用 yum 模块

- name: Install git
  yum:
    name: git
    state: latest

这样,它会自动接受


对于 expect 模块,也许你可以试试这个。

responses:
  (.*)Is this ok(.*): 'y'

其中 是首选和推荐的解决方案,同意安装的命令行参数是根据man yum

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

因此任务是

- name: Install Git via 'yum'
  shell:
    cmd: yum --assumeyes install git
    warn: false
  register: result

进一步问答