zoltan
zoltan

Reputation: 21

ansible import_playbook with role tag

I have setup.yml with multiple roles:

setup.yml:

- hosts: localhost
  roles:
    - { role: file-download, tags: files }
    - { role: setup-nginx, tags: nginx}
    - { role: restart-vm, tags: restartvm }
    - { role: file-upload, tags: upload}
    - { role: intall-vm, tags: installvm}
    - { role: create-backup, tags: backup}
    

From command line I can run:

ansible-playbook -i inventory setup.yml --tags=nginx 
ansible-playbook -i inventory setup.yml --tags=restartvm 

How can I import_playbooks to new.yml playbook and run only roles which have tag nginx and restartvm?

new.yml:

- import_playbook: setup.yml --tags=nginx
- import_playbook:setup.yml --tags=restartvm 

I get following error:

ERROR! Invalid variable name in vars specified for PlaybookInclude: '--tags' is not a valid variable name

Thanks for help

Upvotes: 2

Views: 4124

Answers (1)

xenlo
xenlo

Reputation: 859

This will not work. You can feed import_playbook only with a yaml file name that contains a playbook.

From the doc:

The name of the imported playbook is specified directly without any other option.

But if in your new.yml, you simply have import_playbook: setup.yml and then you specify the tag as ansible-playbook option, it will do the work:

ansible-playbook -i inventory new.yml --tags=my_tag

Upvotes: 3

Related Questions