Páginas

Tuesday, 30 April 2019

Using lookup plugin


I wanted to create a playbook to create a mksysb image and use the date command to append it into the file.
The option that I had is to use one of the lookup plugins to access data from the host where I am running the playbook.
In this case, I used pipe to read the output from a command and used a variable to store the value and use it in my tasks. If I need to run my playbook several times, my mksysb will not be overwritten.



---
- name: Create backup
  hosts: qualys
  vars:
    date: "{{ lookup('pipe', 'date +%Y%m%d') }}"
  tasks:

   - name: Mount NFS filesystem
     aix_filesystem:
       filesystem: /mnt
       nfs_server: unxshr
       device: /Store/ansible/mksysb
       state: mounted

   - name: Run mksysb on "{{ ansible_hostname }}"
     mksysb:
       name: "{{ ansible_hostname }}.{{ date }}.mksysb"
       storage_path: /mnt
       exclude_files: yes
       exclude_wpar_files: yes

   - name: Compress mksysb file
     archive:
       path: "/mnt/{{ ansible_hostname }}.{{ date }}.mksysb"
       remove: yes

   - name: Umount NFS filesystem
     aix_filesystem:
       filesystem: /mnt
       nfs_server: unxshr
       device: /Store/ansible/mksysb
       state: unmounted


References:

Lookup Plugins

No comments:

Post a Comment