【问题标题】:Ansible password setup in user module. It didn't set properly用户模块中的 Ansible 密码设置。它没有正确设置
【发布时间】:2016-05-15 02:56:15
【问题描述】:

我是 ansible 的新手,我正在 digitalocean 中设置我的新实例以配置新用户。基本上,我有设置它的剧本,当我运行剧本时一切正常,但是当我尝试检查我的密码是否有效时,它不起作用。

我做了

sudo apt-get 更新

to 如果密码有效。没有。

---
- name: Configure Server
  hosts: sample_server
  gather_facts: no
  remote_user: root

  vars:
    username: sample_user
    password: sample_password

  tasks:
  - name: Update apt cache
    apt: update_cache=yes

  - name: Safe aptitude upgrade
    apt: upgrade=safe
    async: 600
    poll: 5

  - name: Add my user
    user:
      name: "{{ username }}"
      password: "{{ password }}"
      update_password: always
      shell: /bin/bash
      groups: sudo
      append: yes
      generate_ssh_key: yes
      ssh_key_bits: 2048
      state: present

  - name: Add my workstation user's public key to the new user
    authorized_key:
      user: "{{ username }}"
      key: "{{ lookup('file', 'certificates/id_rsa.pub') }}"
      state: present

  - name: Change SSH port
    lineinfile:
      dest: /etc/ssh/sshd_config
      regexp: "^Port"
      line: "Port 30000"
      state: present
    # notify:
    # - Restart SSH

  - name: Remove root SSH access
    lineinfile:
      dest: /etc/ssh/sshd_config
      regexp: "^PermitRootLogin"
      line: "PermitRootLogin no"
      state: present
    # notify:
    # - Restart SSH

  - name: Remove password SSH access
    lineinfile:
      dest: /etc/ssh/sshd_config
      regexp: "^PasswordAuthentication"
      line: "PasswordAuthentication no"
      state: present
    # notify:
    # - Restart SSH

  - name: Reboot the server
    service: name=ssh state=restarted

  handlers:
  - name: Restart SSH
    service: name=ssh state=restarted

对此有任何想法。谢谢

【问题讨论】:

  • Ansible 用户模块需要密码作为加密值。你检查docs.ansible.com/ansible/… 来生成你的密码吗?
  • 谢谢伙计。知道了! :)

标签: linux ansible ansible-playbook digital-ocean


【解决方案1】:

Ansible 用户模块将密码作为加密值,而 jinja2 过滤器能够处理加密密码的生成。您可以像这样修改您的用户创建任务:

password: "{{ password | password_hash('sha512') }}"

希望对你有帮助

【讨论】:

  • 谢谢。知道了! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-05
  • 1970-01-01
  • 2020-12-22
  • 1970-01-01
  • 2021-04-05
  • 1970-01-01
相关资源
最近更新 更多