Hi,

One way to do this is to append your tasks with a when statement 
<https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#the-when-statement>
 in 
conjunction the special variables 
<https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html>
 inventory_hostname and group_names.

Something like this should work for you:

- name: "this only runs on localhost"
shell: /foo
when: (inventory_hostname == 'localhost')

- name: "this runs on every host in the servers group"
shell: /bar
when: ('servers' in group_names)



On Tuesday, 20 August 2019 15:41:38 UTC+2, Mike Eggleston wrote:
>
> I'm working on a playbook to deploy an internal application to internal 
> hosts. This application is delivered by development to QA in a *.tar.gz 
> file. The file is staged and deployed to QA (by me) in that *.tar.gz file. 
> What I would like/am thinking of is something like:
>
> $ ansible-playbook remote-group -k -e 
> '{"qahost":"qaserver","version":2.75.26.1","path":"/home/app/app_2.75.26.1.tar.gz"}'
>
> and the playbook would be something like:
>
> ---
> - hosts: v2app
>   gather_facts: yes
>
>   vars:
>     qahost: "{{ qahost }}"
>     version: "{{ version }}"
>     remotepath: "{{ path }}"
>     localpath: "/tmp/{{version}}.tar.gz"
>
>   tasks:
>     - name: bring file locally
>       command: scp "{{qahost}}":"{{remotepath}}" "{{localpath}}"
>       local: true
>
>     # localpath referes to /tmp, so using it twice means once on the local 
> server and once on the remote app server
>     - name: copy the deployment file from QA locally
>       copy:src={{localpath}} dest={{localpath}}
>
>     - name: extract the deployment file on the app server
>       command: tar -xzf {{localpath}}
>
>     # still testing, so using /tmp for all updates
>     - name: make a copy of the application
>       shell: rm -rf /tmp/app ; cp -r -p /opt/app /tmp
>
>     - name: sync the new files to the application
>       shell: cd /tmp/app; rsync -a {{localpath}} .
>
>     - name: clean up
>       command: rm -f {{localpath}}
>
> (I'm just typing from memory and haven't syntax checked the above.)
>
> How can I execute a single task of a playbook on the local server and the 
> rest of the tasks on the remote servers? (Is this even possible?)
>
> TIA
>
> Mike
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a82dab25-046b-41e0-b2b2-1d6f068252b6%40googlegroups.com.

Reply via email to