Search code examples
ansibledatastage

How to automate a DataStage job with Ansible?


*****************************[UPDATE]***************************************

I want to edit a script with Ansible. ✔ SOLVED

I found the replace module but in my attempt to run the playbook I get an error. ✔ SOLVED

I want for each value that passes to the variable "result" to do something different. ✘ UNSOLVED

    - name: Automation of a job in DataStage
      hosts: dshost

      vars_prompt:
         - name: project
           prompt: 'Enter the project'
           private: no

         - name: j0b
           prompt: 'Enter the job'
           private: no

      tasks:
         - name: Copying file script to modify then
           copy:
              src: /home/ansible/Downloads/script.sh
              dest: /home/dsadm/script.sh

         - name: Replaces the variables that we've passed
           replace:
               path: /home/dsadm/script.sh
               regexp: '{{ item.regexp1 }}'
               replace: '{{ item.replace }}'
               backup: yes
           with_items:
              - { regexp1: 'project', replace: '{{ project }}' }
              - { regexp1: 'j0b', replace: '{{ j0b }}' }

         - name: Running the script
           command: sh /home/dsadm/script.sh
           register: result

         - name: Check if the script is executed correctly
           debug:
              msg: "The file script was executed without errors"
           when: result.stdout == "\r\nStatus code = 0 \r\n"

The script :

#!/bin/bash

cd /opt/IBM/InformationServer/Server/DSEngine/

. ./dsenv

$DSHOME/bin/dsjob -run project j0b

rtn=$?

**************(UPDATE)********* The output is :

sudo ansible-playbook testJob.yml
[sudo] password for ansible:
Enter the project: dstage1
Enter the job: limits

PLAY [Automation of a job in DataStage] ****************************************************

TASK [Gathering Facts] *********************************************************************
ok: [172.16.2.112]

TASK [Copying file script to modify then] **************************************************
changed: [172.16.2.112]

TASK [Replaces the variables that we've passed] ********************************************
changed: [172.16.2.112] => (item={u'regexp1': u'project', u'replace': u'dstage1'})
changed: [172.16.2.112] => (item={u'regexp1': u'j0b', u'replace': u'limits'})

TASK [Running the script] ******************************************************************
changed: [172.16.2.112]

TASK [Check if the script is executed correctly] *******************************************
skipping: [172.16.2.112]

PLAY RECAP *********************************************************************************
172.16.2.112               : ok=4    changed=3    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

UPDATE 04/07/2019

  • How can I achive that my playbook to does what I want depending on the variable result?

Solution

  • Correct syntax is

    - name: Step one
      hosts: xxx.xx.x.xxx
      vars_prompt:
      ...
    

    This is the reason for the error

    "ERROR! the field 'hosts' is required but was not set"