其他分享
首页 > 其他分享> > 1_0-ansible-authorized_root.yml

1_0-ansible-authorized_root.yml

作者:互联网

---
- name: set public key on remote hosts & set reomte hosts sudoers file
  hosts: all
# 此脚本要求所有的主机 root 用户密码相同
  become: no
  remote_user: root
  vars:
    - remoteuser:
        user1: rhce
  tasks:
    - name: set secondary group for rhce
      user:
        name: "{{ remoteuser['user1'] }}"
        groups: wheel
        append: yes
      register: new_user
    - name: Set authorized key taken from file
      ansible.posix.authorized_key:
        user: "{{ new_user['name'] }}"
        state: present
        key: "{{ lookup('file', '/home/student/.ssh/id_rsa.pub') }}"
    - name: Change file ownership, group and permissions
      ansible.builtin.file:
        path: /etc/sudoers
        mode: '0644'
    - name: Ensure /etc/suders no passwd 
      ansible.builtin.lineinfile:
        path: /etc/sudoers
        insertafter: '^%sudo '
        line: '%wheel   ALL=(ALL:ALL)  NOPASSWD: ALL'

    - name: Change file ownership, group and permissions
      ansible.builtin.file:
        path: /etc/sudoers
        owner: root
        group: root
        mode: '0440'

标签:group,name,ansible,user,file,root,authorized
来源: https://www.cnblogs.com/Anzi-0524/p/16549005.html