How to run only one task in ansible playbook?

前端 未结 7 1141
一向
一向 2020-12-22 16:10

Is there a way to only run one task in ansible playbook?

For example, in roles/hadoop_primary/tasks/hadoop_master.yml. I have "start hadoop jo

7条回答
  •  忘掉有多难
    2020-12-22 16:31

    I would love the ability to use a role as a collection of tasks such that, in my playbook, I can choose which subset of tasks to run. Unfortunately, the playbook can only load them all in and then you have to use the --tags option on the cmdline to choose which tasks to run. The problem with this is that all of the tasks will run unless you remember to set --tags or --skip-tags.

    I have set up some tasks, however, with a when: clause that will only fire if a var is set.

    e.g.

    # role/stuff/tasks/main.yml
    - name: do stuff
      when: stuff|default(false)
    

    Now, this task will not fire by default, but only if I set the stuff=true

    $ ansible-playbook -e '{"stuff":true}'
    

    or in a playbook:

    roles:
    - {"role":"stuff", "stuff":true}
    

提交回复
热议问题