I think what you're looking for is the 'delegate_to' task parameter. If you
wanted the local action to only run once you can combine this with the
'run_once' task parameter -- for your example
- name: bring file locally
command: scp "{{qahost}}":"{{remotepath}}" "{{localpath}}"
delegate_to: localhost
run_once: true
On Tuesday, August 20, 2019 at 6:41:38 AM UTC-7, 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/922ad671-28d8-4c47-b39a-b9cf0177d39f%40googlegroups.com.