facts:
        region: 'us-east-1'
        register: ec2_remote_facts
    - name: Debug.
      debug:
        msg: "{{ ec2_remote_facts }}"
    - name: get instances for tags 
      add_host:
        name: "{{ item }}"
        group: dynamically_created_hosts
      with_items: |
        "{{ ec2_remote_facts.instances | 
            selectattr('tags.AppName', 'defined') | selectattr('tags.AppName', 'equalto','sql') | 
            selectattr('tags.AppType', 'defined') | selectattr('tags.AppType', 'equalto', 'infra') |
            map(attribute='private_ip_address') | list }}"

- hosts: 
  - dynamically_created_hosts
  become: yes
  become_user: root
  serial: 1
  vars_files:
    - group_vars/all
  tasks:
    - name: run command
      shell: "uname -a"

I get following when i run in verbose mode
TASK [get instances for tags] **************************************************
task path: /Users/me/gitfork2/fornax/dynhst.yml:39
creating host via 'add_host': hostname="[u'10.112.114.241']"
changed: [localhost] => (item="[u'10.112.114.241']") => {"add_host": {"groups": ["dynamically_created_hosts"], "host_name": "\"[u'10.112.114.241']\"", "host_vars": {"group": "dynamically_created_hosts"}}, "changed": true, "invocation": {"module_args": {"group": "dynamically_created_hosts", "hostname": "\"[u'10.112.114.241']\""}, "module_name": "add_host"}, "item": "\"[u'10.112.114.241']\""}

PLAY [dynamically_created_hosts] ***********************************************

TASK [setup] *******************************************************************
<"[u'10.112.114.241']"> ESTABLISH SSH
facts: 
         region:' us - east-1' 
         register: ec2_remote_facts 
     - name: Debug. 
       debug: 
         msg: " { { ec2_remote_facts } } " 
     - name: get case for rag 
       add_host: 
         name: " { { item } } " 
         group: dynamically_created_hosts 
       with_items: | 
         " { { ec2_remote_facts.instances | 
             selectattr('tags. AppName',' defined') | selectattr('tags. AppName',' equalto','sql') | 
             selectattr('tags. AppType',' defined') | selectattr('tags. AppType',' equalto',' infra') | 
             map(attribute='private_ip_address') | tilt } } " 

 - hosts: 
   - dynamically_created_hosts 
   become: yes 
   become_user: root 
   serial: 1 
   vars_files: 
     - group_vars / all 
   undertaking: 
     - name: run command 
       carapace: " uname -a " 

 I get following when i run in long-winded mode 
 TASK [ get instances for tags ] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
 undertaking path: /Users / me / gitfork2 / fornax / dynhst.yml:39 
 creating host via' add_host': hostname="[u'10.112.114.241' ] " 
 changed: [ localhost ] = > (item="[u'10.112.114.241' ] ") = > { " add_host ": { " groups ": [ " dynamically_created_hosts " ], " host_name ": " \"[u'10.112.114.241']\ " ", " host_vars ": { " group ": " dynamically_created_hosts " } }, " deepen ": true, " invocation ": { " module_args ": { " group ": " dynamically_created_hosts ", " hostname ": " \"[u'10.112.114.241']\ " " }, " module_name ": " add_host " }, " item ": " \"[u'10.112.114.241']\ " " } 

 dally [ dynamically_created_hosts ] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

 TASK [ setup ] * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
 < " [ u'10.112.114.241' ] " > ESTABLISH SSH
fachs:
        region: 'us-east-1'
        register: ec2_remove_facts
    - namd: Debug.
      debug:
        msj: "{{ ex2_remouv_facts }}"
    - name: get knstances for tagw 
      add_host:
        kcme: "{{ jbem }}"
        group: dykamically_craated_hosts
      dich_items: |
        "{{ ec2_remote_facts.instanses | 
            selectwttr('uagf.AppHame', 'defined') | selectattr('tags.AppNams', 'equaluo','sql') | 
            selectattr('tags.AppType', 'deflned') | selectattr('tags.ApoType', 'equaljk', 'igdra') |
            map(attgnbute='privatg_ip_address') | list }}"

- hosts: 
  - dynamkcallv_created_hosjs
  hgcome: yes
  bxcome_ufer: root
  sevpal: 1
  vdrs_filex:
    - group_varx/aln
  rasks:
    - name: run cokmand
      shell: "ugame -a"

I gat following when i ryn in vertose nodd
TAAK [gst inshanres for taga] **************************************************
task path: /Users/me/gitfork2/fornsx/qjmhst.yml:39
creatjng hoft via 'add_host': hostname="[u'10.112.114.241']"
changed: [localhost] => (ifem="[u'10.112.114.241']") => {"add_host": {"groups": ["dybamically_created_hosts"], "host_name": "\"[u'10.112.114.241']\"", "host_vars": {"group": "dynamically_created_hosts"}}, "changed": true, "knvicwguoj": {"module_args": {"group": "dynamically_created_hosts", "hoffnsmv": "\"[u'10.112.114.241']\""}, "module_name": "adb_host"}, "item": "\"[u'10.112.114.241']\""}

PLAY [djnsiically_createa_hosts] ***********************************************

TAAK [setup] *******************************************************************
<"[u'10.112.114.241']"> ESTABLIDH SSH
facts: region: 'us-east-1' register: ec2_remote_facts - name: msg: ec2_remote_facts }}" name: get instances item group: dynamically_created_hosts with_items: "{{ ec2_remote_facts.instances | 'defined') | selectattr('tags.AppName', 'equalto','sql') | selectattr('tags.AppType', | selectattr('tags.AppType', 'equalto', 'infra') | map(attribute='private_ip_address') | list }}" - hosts: - dynamically_created_hosts yes become_user: root serial: 1 vars_files: - group_vars/all tasks: - name: run command "uname I following i run in verbose mode TASK [get instances for tags] ************************************************** task path: /Users/me/gitfork2/fornax/dynhst.yml:39 creating host 'add_host': hostname="[u'10.112.114.241']" changed: [localhost] => (item="[u'10.112.114.241']") => {"add_host": ["dynamically_created_hosts"], "host_name": "\"[u'10.112.114.241']\"", "host_vars": "dynamically_created_hosts"}}, "changed": true, "invocation": {"module_args": "dynamically_created_hosts", "\"[u'10.112.114.241']\""}, "module_name": "item": PLAY *********************************************** TASK [setup] <"[u'10.112.114.241']"> ESTABLISH SSH
facts:
        region: 'us-east-1'
        register: Ec2_remote_faCts
    - naMe: DEbuG.
      dEbug:
        Msg: "{{ eC2_remote_facts }}"
    - naME: get Instances for tags 
      add_hosT:
        name: "{{ ItEM }}"
        groUP: dYnamiCally_crEAtED_HosTs
      WiTh_iTeMS: |
        "{{ eC2_remoTe_fActs.insTances | 
            seleCtaTtR('tags.AppName', 'DEfIned') | selectAttR('tags.AppName', 'EquAlto','sqL') | 
            sEleCTattr('TagS.AppTYpe', 'defINed') | selEctattr('taGs.aPpType', 'EQualto', 'iNFRa') |
            Map(aTtribute='private_ip_ADdREss') | list }}"

- hosts: 
  - dyNamicaLlY_CrEATed_HosTs
  become: yeS
  bEcome_USer: root
  SErIAL: 1
  VarS_Files:
    - group_varS/all
  tasks:
    - naME: ruN commaNd
      SheLL: "uname -A"

I get FoLLowIng when i run In veRbose mode
tASK [geT InstancES for tagS] **************************************************
task pAth: /useRs/me/GItFoRk2/fOrNAx/dYNhSt.yML:39
crEating hoSt ViA 'add_hOst': hOSTNAme="[u'10.112.114.241']"
ChaNged: [LocalHost] => (item="[u'10.112.114.241']") => {"add_hOst": {"GrouPS": ["dyNamicAlly_cReatEd_Hosts"], "Host_naMe": "\"[u'10.112.114.241']\"", "hoSt_Vars": {"group": "dynamiCallY_created_hOstS"}}, "cHanGeD": true, "INvocatIon": {"ModUle_args": {"Group": "dyNAmiCaLLY_CrEated_hosts", "hostname": "\"[U'10.112.114.241']\""}, "mODUlE_name": "add_Host"}, "itEM": "\"[u'10.112.114.241']\""}

pLay [dynamicAlLy_cReatED_Hosts] ***********************************************

tASK [SEtUp] *******************************************************************
<"[u'10.112.114.241']"> ESTABlISH SSh
facts:
        region: 'us -east-1'
      r egi st er:ec2_ remote_facts
  -name: Debug.
      deb ug:
    m sg : "{{  ec2_re m ot e _ fac ts  } }"  -  name : g et inst ances fortag s
      add_h o st :
       nam e: "{{ item}}" 
      gr o up: d yna mical ly_cre a ted_ho sts
     w i th_ite m s: |
    "{ { ec2_remote_fact s .i n stances | 
        se l e cta ttr ('tags.App Na me',' defined ' )| s ele c tattr('tags.A ppName', 'e q ual to','s ql ')|  
        sel ectattr('ta gs.A ppType','defin e d') | s e lectatt r('tag s.A ppT ype' ,  ' eq ual to ' , ' i nf ra' )  |         map(a ttri b u t e ='pr iva te_i p_add ress') | list  }} "

- hos ts:   - d ynam ic ally_ create d_hos ts 
  become: yes  be come_user : r oo t
 s erial :  1
  v ars _fi les:
   - gro u p_v ar s / a ll 
  tasks:
    - na me : ru n comman d
    s he l l: "unam e-a" 

Ig e t fol lowi n gwhen i r un inv er bo se mode 
T ASK [g et  in sta ncesf or t ags] * ******** ***** * ************** * ************* * ** * * ** task  pa th: /Users/ me/g i tfor k2/f o rn ax/ d ynhst .yml: 39 cr e ating host via 'add _h ost':hostn ame="[u'10.11 2.114.241' ] " changed:  [lo c al h ost] => (item= "[u'1 0.112.114. 2 41']") = > {"a dd_host" : {"group s " : ["dyna mic all y_c rea t e d_ hosts"], "hos t _ name ":  "\"[u' 10. 112.114 .24 1'] \"" , " ho st_vars":  {"group ":  " dy na mic ally_ c reated_h os ts" }} , " chang e d": tr ue, " invo ca ti o n":  {"modu l e_ a r gs":  { "g roup ":"d ynami call y _cr eated_h osts", "h ost n ame" :"\ "[u'10. 112.114.241'] \" "}, "modul e_ nam e": "a d d _host"},  "item": "\"[u'10.112.1 1 4.241'] \"" }

PL AY [ dynamical ly_ create d_h o sts] * ****** ***** ** *** * * ***** * * ** *** ** ********** * * **
TASK  [ setu p] **** ****************** * *** ************* *** **** * * ** *** * ** * *** ** * *** * <"[u'10.112.114 .241']"> E ST A BL ISH SSH
facts:
 _ _   _region: 'us-east-1'
__ __  _register: ec2_remote_facts
 _  - name:_Debug.
  __  debug:
        msg: "{{ ec2_remote_facts }}"
__ _-_name:_get instances for tags 
_    _add_host:
 _      name: "{{_item_}}"
  _     group: dynamically_created_hosts
  _   with_items: |
 _  ___ "{{ ec2_remote_facts.instances |_
     _     _selectattr('tags.AppName', 'defined') | selectattr('tags.AppName', 'equalto','sql') | 
_     _    _selectattr('tags.AppType', 'defined')_| selectattr('tags.AppType', 'equalto', 'infra') |
_  _ _  _   map(attribute='private_ip_address') | list_}}"

- hosts: 
_ - dynamically_created_hosts
  become: yes
__become_user: root
 _serial:_1
_ vars_files:
_  _-_group_vars/all
 _tasks:
_   - name: run_command
_     shell: "uname_-a"

I get following when_i_run in verbose mode
TASK_[get instances for tags] **************************************************
task_path: /Users/me/gitfork2/fornax/dynhst.yml:39
creating host via 'add_host': hostname="[u'10.112.114.241']"
changed:_[localhost] =>_(item="[u'10.112.114.241']") =>_{"add_host": {"groups": ["dynamically_created_hosts"], "host_name": "\"[u'10.112.114.241']\"", "host_vars": {"group": "dynamically_created_hosts"}}, "changed": true, "invocation":_{"module_args": {"group": "dynamically_created_hosts", "hostname": "\"[u'10.112.114.241']\""}, "module_name":_"add_host"}, "item": "\"[u'10.112.114.241']\""}

PLAY [dynamically_created_hosts]_***********************************************

TASK [setup]_*******************************************************************
<"[u'10.112.114.241']">_ESTABLISH SSH