首页 > 解决方案 > 如何使用 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=$?

**************(更新)********* 输出为:

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

标签: ansibledatastage

解决方案


正确的语法是

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

这是错误的原因

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

推荐阅读