多次运行Ansible模块模块

时间:2019-08-22 03:29:46

标签: ansible yaml

我要执行以下操作:

---
- 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

但是,Ansible报告apt是重复的。这是为什么? YAML是否将我的task(命名为install stuff)字典用作字典?以及如何实现我想要的功能:apt然后运行一些命令,然后运行apt?谢谢!

1 个答案:

答案 0 :(得分:2)

  

YAML是否将我的任务(命名为安装资料)当作字典?

  

以及如何实现我想要的:apt然后运行一些命令然后apt?

您需要将这些步骤分解为单独的任务:

---
- 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