I have two playbooks one is fs.yml and nfs.yml..How can i add these two play books in single playbook and should prompt me which one i need to play. My playbooks pasted below. Tried multiple options but always vars_prompt executing first though tag variable is defined.
# cat filesystemcreation.yml
---
# YAML documents begin with the document separator ---
# The minus in YAML this indicates a list item. The playbook contains a list
# of plays, with each play being a dictionary
-
vars_prompt:
- name: HostGroup
prompt: Enter the Hostgroup to run the playbook
private: no
tags:
- local
- name: vgname
prompt: please enter the Volume Group Name
private: no
tags:
- local
- name: lvname
prompt: please enter the Logical Volume Name
private: no
tags:
- local
- name: lvsize
prompt: please enter the Logical Volume Size in MB
private: no
tags:
- local
- name: mountname
prompt: please enter the mountpoint Name
private: no
tags:
- local
hosts: "{{ HostGroup }}"
remote_user: root
tasks:
- name: Creating Logical Volume
lvol:
vg: "{{ vgname }}"
lv: "{{ lvname }}"
size: "{{ lvsize }}"
tags:
- local
- name: Creating File system
filesystem:
fstype: ext4
dev: /dev/mapper/{{ vgname }}-{{ lvname }}
tags:
- local
- name: Mounting File system
mount:
name: "{{ mountname }}"
src: /dev/mapper/{{ vgname }}-{{ lvname }}
fstype: ext4
state: mounted
tags:
- local
# Three dots indicate the end of a YAML document
...
Best Answer
Tags only apply to tasks, and you are using them in vars sections. Also, you have not shown how you are excluding tags, by default all tags run.
There would not be a prompt if you also provided a value of the same name in a location lower on the precedence list than "play vars_prompt".
Personally, I will only use prompts for sensitive information. Ansible is designed for non-interactive use cases, prompts are skipped if not on an interactive shell.
Also consider moving vars and tasks into a role for better reuse. Provide a defaults/main.yml file with some reasonable values for your use case. The playbook can override those vars in a number of different ways.