I want to run a specific task in a playbook to a single host. Is there any better way to do that?

15 views
Skip to first unread message

Rajesh Rajendran

unread,
Apr 26, 2018, 4:46:50 AM4/26/18
to Ansible Project
custom playbook

    ---
    - hosts: swarm_manager
      roles:
      - custom_role

roles/custom_role/tasks/main.yml

    ---
    - name: checking for ip
      shell: docker service ps service | grep Running | head -n1 | awk '{print $1}'
      register: ip
   
    - name: killing the container
      **hosts: "{{ip.stdout}}"**
      shell: docker kill $(docker service ps | grep service | awk '{print $1}')


Reply all
Reply to author
Forward
0 new messages