Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a pre task execute regardless of what tags are passed in?

Tags:

ansible

---    
- name: superduper playbook
  hosts: aws-region1
  remote_user: mesrine
  pre_tasks:
  - include_vars: "{{ env }}/group_vars/vancouver"
    when: region is defined and region == 'van'
  ...snipped...

I want the include_vars task to execute regardless of whatever tags that are passed in. Right now, any tags that are passed in, are filtering out my include_vars pre task.

like image 271
Jacques René Mesrine Avatar asked Dec 09 '15 19:12

Jacques René Mesrine


People also ask

How do you skip tags in Ansible?

If you assign the always tag to a task or play, Ansible will always run that task or play, unless you specifically skip it ( --skip-tags always ). Fact gathering is tagged with 'always' by default. It is only skipped if you apply a tag and then use a different tag in --tags or the same tag in --skip-tags .

How do I control Ansible playbook only on specific hosts?

Using the --limit parameter of the ansible-playbook command is the easiest option to limit the execution of the code to only one host. The advantage is that you don't need to edit the Ansible Playbook code before executing to only one host.

How do I run multiple tags in Ansible?

Along with ansible-playbook command, use --tags or -t flag and pass the tag name to run only that particular task. You can also pass more than one tags to --tags flag by separating the values with commas. To skip particular tags and run all other tags, you can use --skip-tags flag.

How do I run a specific task in Ansible playbook?

The easiest way to run only one task in Ansible Playbook is using the tags statement parameter of the “ansible-playbook” command. The default behavior is to execute all the tags in your Playbook with --tags all .


1 Answers

You can always use the special tag - always - to force a task to always run regardless of the tags specified.

like image 165
ydaetskcoR Avatar answered Oct 24 '22 23:10

ydaetskcoR