Ansible Bootstrap: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Zeile 1: Zeile 1:
−
=Einstellung=
+
<span id="einstellung"></span>
 +
= Einstellung =
 +
 
 
Es liegt hier alles unter ~/ansible
 
Es liegt hier alles unter ~/ansible
−
=Konfig=
+
 
−
*cat ansible.cfg
+
<span id="ansible-konfigurationsdatei"></span>
−
<pre>
+
= Ansible-Konfigurationsdatei =
−
[defaults]
+
 
−
inventory     = ~/ansible/hosts
+
* cat ansible.cfg
−
library        = /usr/share/my_modules/
+
 
−
deprecation_warnings = False
+
<!----->
−
retry_files_enabled = False
+
[defaults]
−
[privilege_escalation]
+
inventory = inventory
−
[paramiko_connection]
+
private_key_file = ~/.ssh/id_rsa
−
[ssh_connection]
+
roles_path = $HOME/ansible/roles
−
[accelerate]
+
<span id="hosts"></span>
−
[selinux]
+
= Hosts =
−
</pre>
+
 
−
=Hosts=
+
* cat inventory
−
*cat hosts
+
 
−
  [bootstrap]
+
<!----->
−
  10.82.232.61
+
10.82.243.96
−
  10.82.232.62
+
  10.82.243.97
 +
  10.82.243.98
 +
  10.82.243.22
 
   
 
   
−
  [bootstrap:vars]
+
  [all:vars]
−
  ansible_connection=ssh
+
  ansible_ssh_pass=123Start$
−
  ansible_ssh_user=xinux
+
  ansible_become_pass=123Start$
−
  ansible_ssh_pass=suxer
+
  ansible_become_method=su
−
ansible_become_pass=sysadm
+
<span id="playbook"></span>
 +
= Playbook =
 +
 
 +
* cat bootstrap.yml
  
−
=Bootstrap=
+
<!----->
−
*cat bootstrap.yml
+
---
−
<pre>
+
- name: Grundlegende Einrichtung der Hosts
−
- hosts: bootstrap
+
  hosts: all
−
  tasks:
+
  become: true
−
  - name: set auth keys
+
  tasks:
−
    authorized_key:
+
    - name: Füge Benutzer xinux zur Gruppe sudo hinzu
−
    user: root
+
      user:
−
    state: present
+
        name: xinux
−
    key: "{{ lookup('file', 'authorized_keys') }}"
+
        groups: sudo
−
    become: true
+
        append: true
−
    become_method: su
+
    - name: Hinterlege SSH publickey bei den Benutzern xinux und root
−
</pre>
+
      authorized_key:
 +
        user: "{{ item }}"
 +
        state: present
 +
        key: "{{ lookup('file', '/path/to/public_key') }}"
 +
      with_items:
 +
        - xinux
 +
        - root
 +
<span id="ausführen"></span>
 +
= Ausführen =
  
−
=Ausführen=
 
 
* ansible-playbook bootstrap.yml
 
* ansible-playbook bootstrap.yml

Version vom 6. Dezember 2022, 06:57 Uhr

Einstellung

Es liegt hier alles unter ~/ansible

Ansible-Konfigurationsdatei

  • cat ansible.cfg
[defaults]
inventory = inventory
private_key_file = ~/.ssh/id_rsa
roles_path = $HOME/ansible/roles

Hosts

  • cat inventory
10.82.243.96
10.82.243.97
10.82.243.98
10.82.243.22

[all:vars]
ansible_ssh_pass=123Start$
ansible_become_pass=123Start$
ansible_become_method=su

Playbook

  • cat bootstrap.yml
---
- name: Grundlegende Einrichtung der Hosts
  hosts: all
  become: true
  tasks:
    - name: Füge Benutzer xinux zur Gruppe sudo hinzu
      user:
        name: xinux
        groups: sudo
        append: true
    - name: Hinterlege SSH publickey bei den Benutzern xinux und root
      authorized_key:
        user: "Vorlage:Item"
        state: present
        key: "Vorlage:Lookup('file', '/path/to/public key')"
      with_items:
        - xinux
        - root

Ausführen

  • ansible-playbook bootstrap.yml