ansible

How to incorporate multiple playbooks in one?


I have got multiple playbooks and want to run them sequentially. Playbooks are supposed to be called with tags, with variables, options such as --skip-tags and limit I tried :

...
- name: Upgrade calico
  when: "ver == '1.24.17'"
  import_playbook: play-kubernetes.yml -l kubernetes-masters -e 'var=e1' --skip-tags=always
  tags: upgrade-calico
...

But playbook failed, because other tags(inside play-kubernetes.yml) were executed(despite specifying only upgrade-calico). I don't want to specify tags explicitly in command line

Are there any other ways to call playbooks sequentially, as if calling them manually one by one?

PS my ansible is ansible 2.9.27


Solution

  • import_playbook does not support to skip particular tags of the imported playbook. The only way to skip tags is to use the --skip-tags command line option of ansible-playbook.


    If you want to automate calling multiple playbooks in a row, with each having different --skip-tags arguments, you could use a shell script, like this:

    run-playbooks.sh

    #!/bin/bash
    
    ansible-playbook playbook1.yml --skip-tags tag_a,tag_b
    ansible-playbook playbook2.yml --skip-tags tag_a,tag_c
    
    # ... and so on
    

    Then run:

    bash run-playbooks.yml
    

    PS: Unfortunately, when you need to use --become and --ask-become-password, the above script would ask for the password multiple times.