How to pass values to an ansible target

  Kiến thức lập trình

I have this inventory file

[app:children]
CL
#BA
#EA
#EB
#EI

[BA]
TEST-cl1 ansible_user=ec2-user modulename=BA

[CL]
TEST-cl1 ansible_user=ec2-user modulename=CL
TEST-cl1 ansible_user=ec2-user modulename=CL
TEST-cl1 ansible_user=ec2-user modulename=CL

[EA]
TEST-cl1 ansible_user=ec2-user modulename=EA

[EB]
TEST-cl1 ansible_user=ec2-user modulename=EB

[EI]
TEST-cl1 ansible_user=ec2-user modulename=EI

Assume my playbook is like this:

---
- name: RUNNING DEPLOYMENT TASKS
  hosts: app
  connection: ssh
  gather_facts: no
  remote_user: ec2-user
  tasks:
    - name: print visit particulars
      shell: echo {{ modulename }} >> f

What will the file “f” contain?

I would like to see “CL” as all but CL is commented off in that app group. However I see EI which I find quite disappointing (do you get why?)

Since I specify hosts: app in my playbook I thought that the children under app will be selected. Why isn’t this so, and how should I code it so that I control where the task is run?

LEAVE A COMMENT