英文:
Ansible: 'user' module 'update_password' register not returning 'rc'
问题
I am resetting Linux user password as below and it resets password. But the register variable resetPwOp
does not contain the attribute rc
.
- name: reset pw linux
user:
name: "{{ userid }}"
update_password: always
password: "{{ passwd | password_hash('sha512') }}"
register: resetPwOp
when: (unlockUserOp is defined) and (unlockUserOp.rc == 0)
The task completes successfully.
TASK [reset pw linux] **********************************************************
changed: [72.118.19.24]
When I try to check resetPwOp.rc == 0
, I get 'dict object' has no attribute 'rc'
but other attributes like shell
, name
, changed
, etc. are available.
resetPwOp
has these values:
"msg": "resetpwop linux: {u'comment': u'72923', u'shell': u'/bin/bash', u'group': 10115, u'name': u'user1', u'changed': True, 'failed': False, u'state': u'present', u'home': u'/home/user1', u'move_home': False, u'password': u'NOT_LOGGING_PASSWORD', u'append': False, u'uid': 1150}
How to be sure the password update successful?
英文:
I am resetting Linux user password as below and it resets password. But the register variable resetPwOp
does not contain the attribute rc
.
- name: reset pw linux
user:
name: "{{ userid }}"
update_password: always
password: "{{ passwd | password_hash('sha512') }}"
register: resetPwOp
when: (unlockUserOp is defined) and (unlockUserOp.rc == 0)
The task completes successfully.
TASK [reset pw linux] **********************************************************
changed: [72.118.19.24]
When I try to check resetPwOp.rc == 0
, I get 'dict object' has no attribute 'rc'
but other attributes like shell
, name
, changed
, etc. are available.
resetPwOp
has these values:
"msg": "resetpwop linux: {u'comment': u'72923', u'shell': u'/bin/bash', u'group': 10115, u'name': u'user1', u'changed': True, 'failed': False, u'state': u'present', u'home': u'/home/user1', u'move_home': False, u'password': u'NOT_LOGGING_PASSWORD', u'append': False, u'uid': 1150}
How to be sure the password update successful?
答案1
得分: 1
But the register variable
resetPwOp
does not contain the attributerc
.但是注册变量
resetPwOp
不包含属性rc
。
Right, that's the expected behavior. According the documentation Common Return Values
正确,这是预期的行为。根据文档中的通用返回值
Ansible modules normally return a data structure that can be registered into a variable, or seen directly when output by the ansible program. Each module can optionally document its own unique return values ...
Ansible模块通常返回一个数据结构,可以注册到一个变量中,或者直接在ansible程序的输出中看到。每个模块都可以选择文档化自己独特的返回值...
and user
module – Manage user accounts - Return Values, there is no such vaule.
还有user
模块 - 管理用户账户 - 返回值,其中没有这样的值。
This is because for rc
这是因为对于rc
Some modules execute command line utilities or are geared for executing commands directly (
raw
,shell
,command
, and so on), this field contains ‘return code’ of these utilities.
一些模块执行命令行实用程序或专为直接执行命令(
raw
,shell
,command
等)而设计,此字段包含这些实用程序的“返回代码”。
How to be sure the password update successful?
如何确保密码更新成功?
If the task executed without errors. This is because the parameter update_password
如果任务执行没有错误。这是因为参数update_password
always
will update passwords if they differ.
always
将在密码不同的情况下更新密码。
and then you may have a look also into changed_when
and failed_when
.
然后,您还可以查看changed_when
和failed_when
。
英文:
> But the register variable resetPwOp
does not contain the attribute rc
.
Right, that's the expected behavior. According the documentation Common Return Values
> Ansible modules normally return a data structure that can be registered into a variable, or seen directly when output by the ansible program. Each module can optionally document its own unique return values ...
and user
module – Manage user accounts - Return Values, there is no such vaule.
This is because for rc
> Some modules execute command line utilities or are geared for executing commands directly (raw
, shell
, command
, and so on), this field contains ‘return code’ of these utilities.
> How to be sure the password update successful?
If the task executed without errors. This is because the parameter update_password
> always
will update passwords if they differ.
and then you may have a look also into changed_when
and failed_when
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论