1playbook 3 plays

This commit is contained in:
2025-02-13 14:49:31 +01:00
parent 33a6317669
commit 262626a5ca

63
setup2.yml Normal file
View File

@@ -0,0 +1,63 @@
---
- name: ssh key pair on localhost
hosts: localhost
tasks:
- name: generate ssh keys
openssh_keypair:
path: "~/.ssh/id_rsa"
size: 2048
become: false
- name: setup target to be managed by ansible
hosts: cibles
tasks:
- name: warn people
ansible.builtin.lineinfile:
path: /etc/motd
create: yes
line: "Host is managed by ansible, manual interaction not recommended"
state: present
- name: history
ansible.builtin.lineinfile:
path: /etc/history
line: "{{ '%Y-%m-%d' | strftime }} - {{ ansible_play_name }}"
state: present
create: true
- name: create account
ansible.builtin.user:
name: ansible
password: "{{ '123Soleil%' | 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"
- name: ansible config on localhost
hosts: localhost
tasks:
- name: reconfigure ansible
community.general.ini_file:
option: "{{ item.option }}"
value: "{{ item.value }}"
section: "{{ item.section }}"
path: /etc/ansible/ansible.cfg
loop:
- { option: "remote_user", value: "ansible", section: "defaults" }
- { option: "become_ask_pass", value: "false", section: "privilege_escalation" }
- { option: "ask_pass", value: "false", section: "defaults" }
delegate_to: localhost