我是ansible的新手,我正在digitalocean中设置新实例以配置新用户。基本上,当我运行playbook时,我有一个设置它的playbook,所有事情都很好,但是当我试图检查我的密码是否有效时,它不起作用。
我做了
更新源
密码是否有效。没有。

---
- 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用户模块将密码作为加密值,jinja2过滤器能够处理加密密码的生成。您可以修改用户创建任务,如下所示:

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

希望对你有帮助

关于linux - 用户模块中的Ansible密码设置。设置不正确,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37234095/

10-16 23:19