1. I have a requirement where I need to pass a hostname so that the ansible 
playbook can take the hostname and do the necessary actions like stopping 
and starting the service of a application.

How can I pass hostname that comes externally to the ansible playbook? 

- hosts: all
  gather_facts: true
  tasks:
    - name: Set services on job servers in {{ work_env }} to {{ work_op }}
      service:
        name: "{{ item }}"
        state: "{{ work_op }}"
      when:
        - inventory_hostname in groups[work_env]
        - inventory_hostname in groups["job"]
      loop:
        - rdcstop
        - ratstop
      loop_control:
        label: Set {{ item }} service on {{ inventory_hostname }} to {{ 
work_op }}.

Here in the above work_env,work_op all are defined in my template. The 
"job" is defined in my inventory file, this tells what host will fall under 
the "jobs" category.  So, if I remove the inventory file, how will ansible 
will be able to read the hostname that comes from external calls? 

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/74db3299-5e55-41c0-9fa0-7d025aaae508%40googlegroups.com.

Reply via email to