0

Am trying to execute the ansible role via commandline option but not able to call/execute only required tagged tasks within called role task. if i don't include the tags in the commandline then it works as expected but i don't want execute full role instead few tasks within the role from commandline.

here is the commandline :

ansible all -i hosts --limit=localhost -e "user_dir=/home/tool_user app_targz_version=app3e-linux-3.1.0.tar.gz test_user_token=16st3!6bc@" -m include_role -a "name=app3" -e '{"apply": [{"tags": 'app_install', 'app_config', 'app_start'"}]}'  -v

so, from above commandline, -e option i used to call the tags but this is not working.

since if I execute above command, it executes full role tasks completely so clearly called tagged didn't work and am 100% sure, those tags are present in the role respective tasks.

your help much appreacited.

vrledu
  • 35
  • 2
  • 8
  • can you show your playbook and your task which contains the tag? – CanciuCostin May 24 '20 at 18:54
  • An approch would be to use tasks splits in several yml files, an calling them all in your main.yml. Thus, you may use "tasks_from" arg from the include_role module. But to be clear, using a playbook is the right thing to do for your case, why won't using them? – Sebcworks May 24 '20 at 19:12
  • I completely agree with you to call roles via playbook but its company's decision not to use playbook instead keep everything at roles level and call them via commandline. so guess I can't go with playbook option. so, somehow I have to get this tagged task working from commandline option only :( at:CanciuCostin, yes i will provide the full role task content. – vrledu May 24 '20 at 20:06
  • 5
    `...but its company's decision not to use playbook instead keep everything at roles level and call them via commandline` => well then it's time to explain "company" this decision does not make any sense and that it is not wise to take decision about how ansible should be used without knowing a single little thing about ansible usage. Stop wasting time, use a playbook: [`include_role` is not intended to be run as an ad-hoc task](https://github.com/ansible/ansible/issues/22983). It's even surprising it works at all when you don't use a tag. – Zeitounator May 24 '20 at 21:01

0 Answers0