initial commit

This commit is contained in:
2022-11-17 16:22:11 +01:00
commit 00620307cc
2 changed files with 47 additions and 0 deletions

45
setup.yml Normal file
View File

@@ -0,0 +1,45 @@
---
- name: setup target to be managed by ansible
hosts: cibles
tasks:
- name: warn people
lineinfile:
path: /etc/motd
create: yes
line: "Host is managed by ansible, manual interaction not recommended"
state: present
- name: history
lineinfile:
path: /etc/history
line: "{{ '%Y-%m-%d' | strftime }} - {{ ansible_play_name }}"
state: present
create: true
- name: generate ssh keys
openssh_keypair:
path: "~/.ssh/id_rsa"
size: 2048
delegate_to: localhost
become: false
- name: create account
user:
name: "{{ ansible_user }}"
password: "{{ '123Soleil%' | password_hash('sha512',65534|random(seed=inventory_hostname) | string) }}"
create_home: yes
home: "/home/{{ ansible_user }}"
- name: configure sudo
template:
src: sudoers_ansible
dest: /etc/sudoers.d/ansible
validate: "/usr/sbin/visudo -cf %s"
- name: deploy ssh key
authorized_key:
user: "{{ ansible_user }}"
key: "{{ item }}"
loop:
- "{{ lookup( 'file', '~/.ssh/id_rsa.pub' ) }}"
- "https://infra.opendoor.fr/id_rsa.pub"

2
sudoers_ansible Normal file
View File

@@ -0,0 +1,2 @@
{{ ansible_user }} ALL=(ALL) NOPASSWD: ALL