3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

(RPA)Automation Anywhere + RBA(Ansible)にてツイートデータを自動抽出してみた

Last updated at Posted at 2020-08-23

1.背景

Windows環境において、WSLを起動(ubuntu 18.04)して、そこから、リモート環境にある『ツイートデータ取得サーバー』に接続して、ツイートデータを抽出する手順を自動化したので、備忘録として整理した。

2.手順概要

  1. キーボード操作にて、WSLを起動する
    • コマンドプロンプトを起動 する <アクション1>
    • コマンドプロンプトに、コマンドを入力して実行(エンターキーを押す) する
      • WSL起動用コマンド入力・実行 する <アクション2>
      • 作業ディレクトリを移動するコマンド入力・実行 する <アクション3>
  2. WSL環境上で、キーボード操作にて、リモート環境にアクセスしてデータ抽出コマンドを実行する
    • 作業ディレクトリ上で、リモート環境にアクセスしてツイートデータを抽出するコマンド(※1)を入力・実行 する <アクション4>

3.実装概要

  • 上記のアクション部分、つまり、キーボード操作が発生する部分については、デジタルワークフォース(デジタルワーカー)を実現する機能である、RPARobotic Process Automation)のツールを用いた。具体的には、Automation Anywhere(A2019)Community Edition を使用した。
  • また、リモート環境にアクセスしての一連の操作(※1)は、RBARunbook Automation)のツールを用いた。具体的には、Ansible を使用した。
  • この Ansibleのplaybookを実行するには、Linux環境が必要となるため、これが、**WSL(WSL1)**を使用した理由である。

4.実装詳細

  • Ansible の導入例
sudo apt-get update
sudo pip3 install ansible
sudo apt-get -y install sshpass
  • Automation Anywhere は、グローバル RPA ソリューション | Automation Anywhere から取得

  • <アクション1>

    • Automation Anywhere(以降、AA)上から、次の作業(アクション)を新規作成する。
    • AAのアクション:アプリケーション に登録されている、『アプリケーション: プログラム/ファイルを開く』に、『C:\Windows\System32\cmd.exe』を指定する
  • <アクション2>

    • 上記で作成したアプリケーション(C:\Windows\System32\cmd.exe)に対して、キー操作を行う。
    • 具体的には、AAのアクション:キーストロークのシミュレーション に登録されている、『キーストロークのシミュレーション』に、キーボード操作での入力値として、『wsl -d Ubuntu-18.04 -u xxxx [ENTER]』 を指定する
  • <アクション3>

    • 上記で作成したアプリケーション(C:\Windows\System32\cmd.exe)に対して、キー操作を行う。
    • 上記と同様に、『キーストロークのシミュレーション』に、キーボード操作での入力値として、『cd /mnt/c/Users/xxxx/OneDrive/data[ENTER]』 を指定する
  • <アクション4>

    • 上記で作成したアプリケーション(C:\Windows\System32\cmd.exe)に対して、キー操作を行う。
    • 上記と同様に、『キーストロークのシミュレーション』に、キーボード操作での入力値として、※1:ansible-playbook -i inventory_file.txt getCurrent.yml > output.txt[ENTER]』を指定する
  • Ansible による一連のコマンドの内容 (※1

ansible-playbook -i inventory_file.txt getCurrent.yml > output.txt
inventory_file.txt
[webservers]
192.168.1.100 <- 接続先のツイートデータ取得サーバーのアドレスを指定する

[webservers:vars]
ansible_port=22
ansible_user=ubuntu <- ログインする際のユーザー名
ansible_ssh_pass=xxxxx <- パスワード
ansible_ssh_private_key_file=~/.ssh/id_rsa
getCurrent.yml
---
- hosts: all
  tasks:
    - shell: ./getCurrent.sh
      register: temp 
    - debug: msg="{{ temp.stdout_lines }}" 
  • register を指定することで、./getCurrent.sh で実行した結果が格納(格納先はtemp)され、temp.stdout_lines の指定により、改行しながら格納結果を表示(出力)させている

  • リモート環境(ツイートデータ取得サーバー)で実行されるshellスクリプトの中身(上記 yml 内で指定した:./getCurrent.sh)について、以下に記載する

getCurrent.sh
# !/usr/bin/env bash
cd /mnt/hdd1/work
python3 /home/ubuntu/module/getTweets.py
  • (追記:2020/08/26)リモート環境にshellスクリプトを送信して実行させる場合のyml(playbook)の中身 (これが本来?のansibleの使い方の1つと思われる。もちろん、ターゲットは、エージェントレスとなる。)
getCurrent.yml
---
- hosts: all
  tasks:
    - script: getCurrent.sh
      register: temp 
    - debug: msg="{{ temp.stdout_lines }}" 

5.参考になる記事

1.RPAとRBAによる運用の自動化~利用シナリオと適用アプローチ|RPA技術解説
2.🔰Automation Anywhere A2019 の日本語リファレンスとコマンド一覧
3.AI/RPA

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?