Aleksey Budaev
Aleksey Budaev

Reputation: 134

How do I agree to install the package?

My playbook:

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

I execute the command sudo ansible-playbook test.yaml, but I get an error.

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

MSG:

non-zero return code

Upvotes: 0

Views: 853

Answers (2)

U880D
U880D

Reputation: 12142

Whereby the currently accepted answer is the preferred and recommend solution, the command line parameter to agree on installation is according man yum

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

Therefore the task would be

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

Further Q&A

Upvotes: 0

Tolis Gerodimos
Tolis Gerodimos

Reputation: 4408

One way would be to avoid the expect module entirely and use the yum module instead

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

This way, it will autoaccept


For expect module maybe you could try this.

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

Upvotes: 2

Related Questions