awxのバックアップ/リストア (tower-cli)

検証環境のawxで、awxがバックエンドで使用しているpostgresの調子が悪く、何度もawxが落ちる事象が発生しました(最終的にはawxをアップグレードしたら解消しました)。その際に、awxのバックアップ/リストアを行ったので備忘録として残しておきます。

 

概要

  • tower-cliコマンドの設定のエクスポート、インポートを使ってawxのバックアップ/リストア操作を行えます。
    • tower-cli receiveコマンドを使ってawxの設定情報をjsonファイルとしてエクスポート
      (tower-cli receive --all > xxx.json)
    • tower-cli sendコマンドでjsonファイルをawxにインポート
      (tower-cli send xxx.json)
  • 完全なリストアではなく設定のインポートのため、バックアップ後に消えたオブジェクトは復元するが、バックアップ後に作成されたオブジェクトは消えない。(消えたデータの復元)
tower-cliとは
  • Ansible Tower のコマンドツール
  • Tower 内にある大半のオブジェクトを取得、作成、変更、削除することができる
    • プレイブック実行の起動 (例: Jenkins、TeamCity、Bamboo など)
    • ジョブステータスの確認
    • 組織、ユーザー、チームなどのオブジェクトの迅速な作成
  • 既に開発は終わり、後続のawxコマンドが出ている現在はこちらが推奨

ansible公式: tower-cli の概要 — Ansible Tower API Guide v3.1.4

Reference: https://tower-cli.readthedocs.io/en/latest/cli_ref/

手順

tower-cliのセットアップ

  1. tower-cliのインストール

コマンド: pip/pip3 install ansible-tower-cli

自動生成された代替テキスト: 
Croot@sp-centos7-awx01]#pip3installarsible-towe「-cli
Collectingansible-towe「-cli
Downloadingansible-towe「-cliー3.3.9.士a「.z(203kB)
Requirementalreadysatisfied:six>:l.7.2in/us「川ocaし勹ib/python3.6/site-p
ckages(fromansible-towe「-cli)(1.15.の
Requirementalreadysatisfied:Py〉:3.10in/us「川ocaしⅢ団4/py日13.6/sit
e-packages(f「omansible-towe「-cli)(5.3.1)
Collectingclickく7.0
Downloadingclickー6.7ーpy2.py3ー「肥ーany.同引(71kB)

  1. Ansible AWXの情報をconfigに設定する。
    • hostの設定: tower-cli config host <http://" ansible awx IP"/>
    • userの設定: tower-cli config username <admin>
    • passwordの設定: tower-cli config password <password>
    • ssl証明書の無効化: tower-cli config verify_ssl false

自動生成された代替テキスト: 
Croot@sp-centos7-awx01]#t01i肥「一cli
vonfigurationupdatedsuccessfully.
root@sp-centos7-awx01]#t01i肥「一cli
しonfigurationupdatedsuccessfully.
Croot@sp-centos7-awx01]#t01i肥「一cli
oonfigurationupdatedst-にcessfully.
root@sp-centos7-awx01]#t01i肥「一cli
vonfigurationupdatedsuccessfully.
Croot@sp-centos7-awx01]#t01i肥「一cli
config
config
config
config
config
s士http:〃192.168.2.3:31497
usernameadrnin
passwo「dpasswo「d
ve「ify-sslfalse

 

  1. configの確認

コマンド: tower-cli config

User optionsに設定した情報が表示される

自動生成された代替テキスト: 
[root@sp-centos7-awx01]#士肥「一clic紆ig
#し「opti(setwitht(*er-cliconfig;sto「in7.t(»er—cli.cfg).
http:〃192-168-2-3:31497
aånin
.し「Tれ:
passyord:passwrd
.verify—ssl:F引
#Defaults.
Color:
F引
げコ」「e:
・verbose:F引
:(e--t1:F引
.formt:
・杙ificate:
descripti1-01:F引

バックアップ

オブジェクトのバックアップ

コマンド: tower-cli receive --all > xxx.json

※オプション(--all)を変えれば一部のオブジェクトだけエクスポートも可能(リファレンス参照)自動生成された代替テキスト: 
Croot@sp-centos7-awx01]#tot/肥「一cli「eceive--all>aw廴badく叩ー20210124.jsor

出力内容の確認

自動生成された代替テキスト: 
[root@sp-centos7-awx01~]#catawxーback(ー20210124.json
し樰e「
admin"
last—name":
"fi「stゴ肥":
username
asset—type"・
asset—relat1":{
name":"Default"
asset_type:organizati61"
is—superuse「":t代旧
email":"「00t38st"
team":[]
name
roles":[
Admin"

リストア

オブジェクトのリストア(バックアップファイル(.json)のインポート

コマンド: tower-cli send xxx.json

自動生成された代替テキスト: 
[root@sp-centos7-awx01
USER[admin]
ORGANIZATION(Default]
Assetup士0date
]#士肥「-clisendawxーback!一20210124.json
Assetup士0date
All「olesa「eup士0date
CREDENTIAL[匪「「0Credential]
Assetup士0date
All「olesa「eup土0date

 

※どこがリストアされたかは一目瞭然

自動生成された代替テキスト: 
WORKFLOWCset_up_idrac]
Checkingonwo「k日on-nodes
C「eatedwo「k日owse士ュ膾」d「ac
Su「veyup士0date
BuiIdingnewworkflownodes
BuiIdingwo「k日ownode「引a士ions
Alllabelsa「eup土0date
All「olesa「eup土0date
AⅡschedulesa「eup土0date