ユーザが存在する場合は、そのプレイヤーのpwを変更するプレイブックを作成します。 プレイブックはユーザーを受け取り、そのユーザーのpwを変更することができます。ループでレジスタを使用する場合
今のところimがループのために空であるという問題を抱えていますが、私はwith_items:{{user_exists.results}}を使ってみましたが、これは何とかうまくいきません。 (http://docs.ansible.com/ansible/playbooks_loops.html#using-register-with-a-loop)
何か問題がありますか?
Brで、 Numblesix
---
-
become: true
become_method: sudo
hosts: xetest
name: "Updates the password of given User if exists"
tasks:
-
ignore_errors: true
name: "Check if User exists"
register: user_exists
shell: "grep -q {{ item.key }} /etc/passwd &>/dev/null"
with_dict: "{{ users }}"
-
debug:
var: user_exists
-
debug:
msg: "User name is {{ item.key }} and hash is {{ item.value.passwd}} and return code is: "
with_dict: "{{ users }}"
-
debug:
var: user_exists
with_items: "{{user_exists.results }}"
-
name: "updating password for given User"
user: "name={{ item.key }} update_password=always password={{ item.value.passwd}} createhome=no"
when: user_exists.rc == 0
with_dict: "{{ users }}"
with_items: "{{ user_exists.results }}"
vars:
users:
foo:
passwd: $6$random_salt$12A.ar9eNDsgmds3leKoCDZPmq7OHLvhBtQg/Q3K2G/3yeEa/r8Ou4DxJpN6vzccewugvZt7IkfCbHFF2i.QU.
エラーになります! with_items WITHOUT
duplicate loop in task: items
: "{{user_exists.results}}" イムは、このエラーに私のテストでは
"failed": true, "msg": "The conditional check 'user_exists.rc == 0' failed.
The error was: error while evaluating conditional (user_exists.rc == 0):
'dict object' has no attribute 'rc'
うわー、それは働いています:)もっと少し説明できますか?私は>&dev/nullと違ったrcを取得しますが、もう一度チェックしてください。ユーザーコードが存在するかどうかチェックするようになりました+ - 名前: "指定されたユーザーのパスワードを更新しています" user: "name = {{item.item {{ユーザー}} " with_items:" {{ユーザー}} {パスワード} = {パスワード} {パスワード} user_exists.results}} " – Sandro
こんにちは@Sandro、私はあなたが私にもっと説明してほしい部分が不明です。 –