【问题标题】:Adding new sudo user using ansible - "password": "NOT_LOGGING_PASSWORD" message使用 ansible 添加新的 sudo 用户 - "password": "NOT_LOGGING_PASSWORD" 消息
【发布时间】:2016-11-28 04:37:27
【问题描述】:

我正在使用 Vagrant(Virtual Box 提供商)来设置本地虚拟机。我还使用 ansible 和更具体的 ansible_local(Vagrant 插件)将一些工具部署到 VM 中。

最初我正在尝试按照 ansible 文档创建一个新用户。

---
- name: Master Node
hosts: 127.0.0.1
connection: local
user: root
vars_files:
    - vars/vars.yml
vars:
    username: nikolas

tasks:
- name: Adding user
  user: name={{username}} shell=/bin/bash groups=root append=yes password={{pass}}
  sudo: yes

- name: Placing RSA key
  authorized_key: user={{username}} key="{{ lookup('file', 'id_rsa.pub') }}"
  sudo: yes

当我运行 playbook 时,我收到以下消息:

播放 [主节点] ****************************************** ******************

收集事实 ********************************************* ****************** 好的:[127.0.0.1]

任务:[添加用户] ******************************************* ********* 已更改:[127.0.0.1] => {“已更改”:true,“comment”:“”,“createhome”:>true,“group”:1001,“groups”:“root”,“home”:“/ home/nikolas", "name": >"nikolas", "password": "NOT_LOGGING_PASSWORD", "shell": "/bin/bash", >"state": "present", "system": false, "uid ": 1001}

任务:[放置 RSA 密钥] **************************************** *************** 已更改:[127.0.0.1] => {“已更改”:true,“key”:“ssh-rsa >AAAAB3N ....public_rsa_key”,“key_options”:null,>“keyfile”:“/home/desmotes/ .ssh/authorized_keys", "manage_dir": true, >"path": null, "state": "present", "unique": false, "user": "nikolas"}

播放回顾 ************************************************ *********************** 127.0.0.1 : ok=4 changed=2 unreachable=0 >failed=0

“密码”:“NOT_LOGGING_PASSWORD” 结果,当我尝试在 VM 中以 nikolas 身份登录时出现身份验证错误。

你知道我的错误在哪里吗?

谢谢

【问题讨论】:

    标签: vagrant ansible ansible-playbook


    【解决方案1】:

    我认为您需要像这样修改user 创建任务:

    - name: Adding user
      user: name={{username}} shell=/bin/bash groups=root append=yes password={{ pass | password_hash('sha512') }}
      sudo: yes
    

    希望对你有所帮助。

    【讨论】:

    • 我尝试了您的代码,但收到了失败的消息。例如失败:[127.0.0.1] => {"failed": true} 消息:此模块需要 key=value 参数 致命:所有主机都已失败 -- 正在中止
    • 你走哪一步了?能否请您粘贴完整的曲目。
    • 我改变了策略,我使用了 password_hash('sha512')。例如,我添加了这个 var : > password: "{{'password'|password_hash('sha512')}}" 并更改了一些用户任务,例如: > user: name={{username}} password={{ password }} 最后没有任何改变:ok: [127.0.0.1] => {"append": false, "changed": false, "comment": "", "group": 1001, "home": "/home/nikolas ", "move_home": false, "name": "nikolas", "password": "NOT_LOGGING_PASSWORD", "shell": "/bin/sh", "state": "present", "uid": 1001}
    • 谢谢帮助。我使用了您的建议并添加了保险库机制,最后我的 ansible-playbook 没问题。在以下链接中,您将找到我正确的commit
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-18
    • 1970-01-01
    • 2017-02-14
    • 2020-06-17
    • 2016-11-11
    • 2020-10-13
    • 1970-01-01
    相关资源
    最近更新 更多