Ansible处理程序,用于在第一次登录时更改密码



您好,正在使用一个ansible脚本创建ssh用户,并在第一次登录时强制更改密码。这个想法是可以的,但对于带有python 3.7.3版本的ansible 2.7.7,处理程序似乎是不可以的。以下是实际脚本和实际语法

- name: Add {{ user }} user
user:
name: "{{ user }}"
state: present
groups: "rebel"
shell: /bin/bash
password: $1$Somesdfs$AVJ/Zl.pfCejORtGpE4p..
update_password: on_create
notify: force change password

handlers:
- name: force change password
command: "chage -d 0 {{ user }}"
when: user.changed

这是错误

致命:〔192.168.12.147〕:失败!=>{"reason":"语法错误装载YAML。\n找不到预期的"-"指示符\n\n错误似乎在'/home/klevin/Rebel/ansible user sync/edit_users/internal_add_users.yml':第57行,第1列,但根据确切的语法问题。\n\n有问题的行显示为be:\n\n\n转发器:\n^此处\n"}

第57行是处理程序行启动的位置

您发布的yam文件似乎存在语法问题,特别是空格和"-"符号。

我更新了yaml,因为没有提供完整的yaml,如下所示,它成功运行,没有任何语法错误。

- name: "Test"
hosts: localhost
connection: local
tasks:
- name: Add {{ user }} user
user:
name: "{{ user }}"
state: present
groups: "rebel"
shell: /bin/bash
password: $1$Somesdfs$AVJ/Zl.pfCejORtGpE4p..
update_password: on_create
notify: force change password
handlers:
- name: force change password
command: "chage -d 0 {{ user }}"
when: user.changed

确保"主机"、"任务"one_answers"处理程序"具有正确的格式/间距,并在它们下面的行中显示"-name:">

最新更新