On torsdag 9. november 2017 10.50.54 CET Jörg Kastning wrote:
> let me explain my scenario first, before I come to my question.
>
> We run most of our linux servers as virtual machines in VMware vSphere
> Clusters. I would like to use a playbook that takes a snapshot from a vm
> befor it runs further tasks on the target node. In case of a broken system
> after an upgrade I could revert the snapshot and I'm up and running again.
>
> Here is a not working example playbook:
> ---
> - hosts: localhost
> connection: local
Instead of using hosts: localhost, you could use the inventory hostname or the
group.
Since you have connection: local it will run on the controller host.
The benefits is that if you use "register: some_variable" then the variable
will be registered on the host and not localhost.
> tasks:
> - name: snapshot operation
> vmware_guest_snapshot:
> hostname: "{{ vc }}"
> username: "{{ vc_user }}"
> password: "{{ vc_passwd }}"
> datacenter: "{{ vc_datacenter }}"
> folder: /mydatacenter/vm/"{{ item.folder }}"/
> name: "{{ item.vm }}"
> state: absent
> snapshot_name: snap1
> description: "Fuegen Sie hier Ihre Beschreibung ein"
> validate_certs: false
> delegate_to: localhost
> with_item:
> - "{{ nested_list }}"
Then you could use "register: status_snapshot" on this task, and check it's
status in the next play.
> - hosts: staging
> tasks:
> - name: run yum -y update
> yum:
> name: "*"
> state: latest
Variables in one play is available in subsequent play in the same playbook.
So you can then use the variable status_snapshot to decide what to do in this
play.
> The group 'staging' in the second play contains the hosts that should be
> updated after a snapshot was taken. In the example above ansible would at
> first try to create snapshots and at second update my nodes whether the
> snapshot creation was successful or not. I have no idea how to create a
> dependency from the second play to the first one.
>
> Do you understand what I'm trying to accomplish? Do someone have an idea on
> how to solve this?
Yes it's understandable what you are trying to do, hopefully my suggestion give
you a tip on how to achieve it.
--
Kai Stian Olstad
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2260906.jXT4sE3nvg%40x1.
For more options, visit https://groups.google.com/d/optout.