Minh Nghĩa
Minh Nghĩa

Reputation: 1053

Run Ansible module module multiple time

I want to do the following:

---
- name: install stuff
  hosts: h1
  tasks:
  - name: install stuffs
    tags: install_stuffs
    apt:
      name: "{{ packages }}"
      update_cache: yes
    shell: |    # multiline string, right?
      apt-key bla_bla
    apt:
      name: other_package
    vars:
      packages:
      - python3
      - nano

However, Ansible reports that the apt is duplicated. Why is that? Does YAML treat my task (named install stuff) a dictionary? And how to achieve what I want: apt then run some command then apt? Thanks!

Upvotes: 0

Views: 173

Answers (1)

Matt P
Matt P

Reputation: 2625

Does YAML treat my task (named install stuff) a dictionary?

Yes

And how to achieve what I want: apt then run some command then apt?

You need to split these steps out into separate tasks:

---
- name: install stuff
  hosts: h1
  tasks:
  - name: install stuffs
    tags: install_stuffs
    apt:
      name: "{{ packages }}"
      update_cache: yes
    vars:
      packages:
      - python3
      - nano

  - name: run stuff
    shell: apt-key bla_bla

  - name: install more stuff
    apt:
      name: other_package

Upvotes: 2

Related Questions