solution
This commit is contained in:
55
setup.yml
Normal file
55
setup.yml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
---
|
||||||
|
- name: setup target to be managed by ansible
|
||||||
|
hosts: cibles
|
||||||
|
vars_prompt:
|
||||||
|
name: password
|
||||||
|
prompt: "ansible user password ? "
|
||||||
|
private: true
|
||||||
|
tasks:
|
||||||
|
- name: warn people
|
||||||
|
ansible.builtin.lineinfile:
|
||||||
|
path: /etc/motd
|
||||||
|
create: yes
|
||||||
|
line: "Host is managed by ansible, manual interaction not recommended"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- password | length > 14
|
||||||
|
fail_msg: "no blank password !"
|
||||||
|
|
||||||
|
- name: history
|
||||||
|
ansible.builtin.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
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: ansible
|
||||||
|
password: "{{ password | password_hash('sha512',65534|random(seed=inventory_hostname) | string) }}"
|
||||||
|
create_home: yes
|
||||||
|
home: /home/ansible
|
||||||
|
|
||||||
|
- name: configure sudo
|
||||||
|
community.general.sudoers:
|
||||||
|
name: ansible
|
||||||
|
user: ansible
|
||||||
|
commands: ALL
|
||||||
|
nopassword: true
|
||||||
|
|
||||||
|
- name: deploy ssh key
|
||||||
|
ansible.posix.authorized_key:
|
||||||
|
user: ansible
|
||||||
|
key: "{{ item }}"
|
||||||
|
loop:
|
||||||
|
- "{{ lookup( 'file', '~/.ssh/id_rsa.pub' ) }}"
|
||||||
|
- "https://infra.opendoor.fr/id_rsa.pub"
|
||||||
Reference in New Issue
Block a user