deployAnsible.yml 1.14 KB
---
- hosts: new-host
  become: true
  tasks:
    - name: New Ansbile Group
      group:
          name: ansible
          state: present
    - name: Allow 'ansible' group to have passwordless sudo
      lineinfile:
        dest: /etc/sudoers
        state: present
        regexp: '^%ansible'
        line: '%ansible ALL=(ALL) NOPASSWD: ALL'
        validate: 'visudo -cf %s'
          
    - name: New Ansible User
      user:
          uid: 1111
          home: /home/ansible
          name: ansible
          group: ansible
          shell: /bin/bash
          system: no
          createhome: yes
      
    - name: Grant Permission
      command: usermod -aG sudo ansible
    
    - name: New Directory for authorized_keys
      file:
             path: "{{ item.path }}"
             owner: "{{ item.owner }}"
             group: "{{ item.owner }}"
             state: directory
      with_items:
             - { owner: ansible, path: /home/ansible/.ssh }

    - copy:
            src: /tmp/configuration/authorized_keys
            dest: /home/ansible/.ssh/authorized_keys
            owner: ansible
            group: ansible
            mode: 0600
# Update 2