未解決
Moderator
•
6.5K メッセージ
1
192
【七転び八起き】PowerStore3.0でAnsibleを使うときの注意 yml sample 編
今回はPowerStore3.0でSample ymlを使ってみた時に気が付いた話です。
七転び八起きなので結構余計なつまづきがありますが備忘録もかねてそのまま書きます。
問題:search_volumes.ymlを使ったら該当のVolumeが全部出てこない。
使ったyml 書式
# This playbook fetches all the volumes whose name matches the regex pattern.
---
- name: Volumes whose names match the regex pattern
hosts: localhost
connection: local
vars:
array_ip: 'XX.XX.XX.XX'
user: 'xxxxx'
password: 'XXXXXXXX'
verifycert: False
pattern: 'ここに検索したいVolumeの文字列をいれる' →今回はTest(Case sensitiveなので注意!)
collections:
- dellemc.powerstore
tasks:
- name: Get the details of all the Volumes
info:
array_ip: "{ {array_ip}}"
user: "{ {user}}"
password: "{ {password}}"
verifycert: "{ {verifycert}}"
gather_subset:
- vol
register: subset_result
# The set_fact generates a list of the volume names using the details of volumes(the output of the previous task).
- set_fact:
all_volumes_names: "{ { subset_result['Volumes'] | map(attribute='name') | list }}"
# This task gets the list of the volumes which match a regular expression. The syntax of the regular expression is same as in python.
- name: List of the all the volume names which match the pattern
debug:
msg: "{ { all_volumes_names | select('match',pattern ) | list }}"
結果>VolumeListは省略
PLAY RECAP *********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
成功したように見えるのですが、リストされたボリューム数とpstcli volume show でリストされるTestXXXXのつくボリューム数に差がある!(yml結果のほうが少ない。。)
原因:pstcli volume showでは一度に最大100個のボリュームまでしかlist されない(volume show -allだと全部出力される)のでその中で確認できたTestとつくVolumeだけ抜き出してきた。
対応策:使ったyml書式に以下の一文を追加して全部のボリュームを確認するようにする。
- name: Get the details of all the Volumes
info:
array_ip: "{ {array_ip}}"
user: "{ {user}}"
password: "{ {password}}"
verifycert: "{ {verifycert}}"
gather_subset:
- vol
all_pages: True
register: subset_result
上記を追加したymlで再度チャレンジ!
Testとつくボリュームすべてがリストされた!
(結果はあまりにVolumeが多いので割愛)
おまけの注意:Path 切ってないとyml失敗します・・・
エラー:
# ansible-playbook test.yml
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the
controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 9
2021, 16:02:49) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]. This feature will be
removed from ansible-core in version 2.12. Deprecation warnings can be disabled
by setting deprecation_warnings=False in ansible.cfg.
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
ERROR! couldn't resolve module/action 'volume'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/home/ayasaito/ansible_collections/dellemc/powerstore/docs/samples/test.yml': line 16, column 5, but maybe elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: Create multiple volumes
^ here
解決策:以下でパスを切る
# export ANSIBLE_COLLECTIONS_PATHS=$ANSIBLE_COLLECTIONS_PATHS:<ansible collectionが入っているパス>
上記をしてからもう一度実行
# ansible-playbook test.yml
中省略
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
成功!