Я хочу создать доступную роль для добавления пользователя с помощью ssh_keys
├── ansible.cfg
├── hosts
├── playbooks
│ └── add_user.yml
└── roles
└── add-user
├── files
│ ├── ansible.pub
│ ├── dhirendra.pub
│ ├── nitigyas.pub
│ └── vinayaks.pub
├── tasks
│ └── main.yml
└── vars
└── main.yml
Файл tasks / main.yml:
---
- name: AddUser in the server
user:
name: ansible
password: $6$sHQAZJ32E$ujHauabN7ZTbOQ/zhT5899EIaFErOecXYvTEyhekexy4dydsAXTGdUpaB8M4fQf2UGpZgX/Zg2Uv6areeuv/r0
comment: Ansible Configuration Mgmt
shell: /bin/bash
- name: Add SSH key to users home direcotory
authorized_key:
user: "{{ item.name }}"
key: "{{ item.file }}"
state: present
with_items:
- ssh_vars
...
Файл vars / main.yml:
---
ssh_vars:
- { name: "ansible" , file: 'ansible.pub' }
пока я запускаю эти роли, я получаю следующую ошибку
PLAY [backend1.greengst.com] *************************************************************************************************************
TASK [add-user : AddUser in the server] **************************************************************************************************
ok: [backend1.greengst.com]
TASK [add-user : Add SSH key to users home direcotory] ***********************************************************************************
fatal: [backend1.greengst.com]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'name'\n\nThe error appears to have been in '/etc/ansible/roles/add-user/tasks/main.yml': line 9, 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: Add SSH key to users home direcotory\n ^ here\n"}
Debugger invoked
Проблема в том, как вы используете with_items
: bare переменные уже довольно давно не поддерживаются.
Исправьте свой цикл следующим образом: with_items: "{{ ssh_vars }}"