如何使用Ansible自动化DataStage作业?

时间:2019-07-01 19:43:41

标签: ansible datastage

***************************** [更新] *************** ************************

我想用Ansible编辑脚本。 ✔已解决

我找到了替换模块,但是在尝试运行剧本时遇到错误。 ✔已解决

我希望对传递给变量“结果”的每个值执行不同的操作。 ✘未解决

    - 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"

脚本:

#!/bin/bash

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

. ./dsenv

$DSHOME/bin/dsjob -run project j0b

rtn=$?

**************(UPDATE)*********输出为:

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

更新04/07/2019

  • 如何根据可变结果使剧本达到我想要的目标?

1 个答案:

答案 0 :(得分:0)

正确的语法是

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

这是错误的原因

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