ur8qnw
Last Updated: February 25, 2016
·
38.95K
· dorfsmay

How can you run only one task out of a playbook, for debug purposes

Use tags!

for example:

---
hosts: all
gather_facts: no

    - name: set minus o vi
  lineinfile: dest=/root/.profile state=file create=yes state=present insertafter=EOF regexp='' line='set -o vi'

  - name: create /export/data directory
    action: command mkdir -p /export/build creates=/export/data
   tags:
     - debug

- name: install all packages
  apt: pkg=$item install_recommends=yes
  with_lines: cat /var/tmp/packages.all

Running the following will only run the create directory task:

ansible-playbook setup.playbook.yaml --tags debug

Or even better, with -vvv for debug mode:

ansible-playbook -vvv setup.playbook.yaml --tags debug

2 Responses
Add your response

4949

Also new in 1.1, "ansible-playbook playbook.yml --step" can let you interactively step through playbooks and decide what to run.

over 1 year ago ·
6237

and in ansible 1.2+ you can use:

--step --start-at-task=tasknamehere

and it will do stepped task execution starting at the first task matching the string you put in

over 1 year ago ·
Filed Under