1

ansibleを使用してユーザーを作成しようとしていました。users という変数を作成し、ユーザーのリストとその他のオプションをその中に入れました。ここにあります:

users:
  - { user_name: "user1", sudo_type: "full", password: "pass", ssh_pub_key: "ssh-rsa AAAAB..." }
  - { user_name: "user2", sudo_type: "limited", password: "somepass", ssh_pub_key: "ssh-rsa AAAAB3..." }

次に、次のタスクを作成しました。

- name: create local users
  local_action: user name={{ users.user_name }} createhome=yes state=present password={{ users.password }} shell=/bin/bash generate_ssh_key=yes ssh_key_type=rsa ssh_key_comment="{{ ansible_hostname }}-{{ users.user_name }}"

Playbook を実行すると、次のエラーで失敗しました。

fatal: [10.60.16.1]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'list object' has no attribute 'user_name'\n\nThe error appears to have been in '/root/ansible-builds/roles/users/tasks/main.yml': line 11, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: create local users\n  ^ here\n"}

問題はどこにありますか?

4

1 に答える 1