Ansible: Unterschied zwischen den Versionen

Aus Info-Theke
Zur Navigation springen Zur Suche springen
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 24: Zeile 24:
ssh-copy-id $HOST
ssh-copy-id $HOST
ansible all -a "tail -1 /etc/shadow"
ansible all -a "tail -1 /etc/shadow"
#
ANS_HOME=/home/ws/ansible/$HOST
cd $ANS_HOME
ansible-playbook playbook/i_10_basic.yaml
</syntaxhighlight>
== Tipps ==
<syntaxhighlight lang="yaml">
- name: Using dict2items
  ansible.builtin.debug:
    msg: "{{ item.key }} - {{ item.value }}"
  loop: "{{ tag_data | dict2items }}"
  vars:
    tag_data:
      Environment: dev
      Application: payment
- name: Add several users
  ansible.builtin.user:
    name: "{{ item.name }}"
    state: present
    groups: "{{ item.groups }}"
  loop:
    - { name: 'testuser1', groups: 'wheel' }
    - { name: 'testuser2', groups: 'root' }
     
</syntaxhighlight>
</syntaxhighlight>

Aktuelle Version vom 23. April 2025, 15:17 Uhr

Links[Bearbeiten]

Zielsetzung[Bearbeiten]

Hilfestellung für die Serververwaltungssoftware Ansible.

Installation neuer Server[Bearbeiten]

STD_USER=wk
HOST=host1.example.com
apt install ansible
adduser $STD_USER
echo "= store the password at a secure place"
adduser --firstuid=260 --firstgid=260 ansadm
echo "= add ansadm to the wheel users without password: ALL=NOPASSWD: ALL"
vi /etc/sudoers
cp /etc/hostname /etc/hostname.orig
echo $HOST >/etc/hostname
reboot

Aktionen auf dem lokalen Rechner[Bearbeiten]

HOST=host1.example.com
sudo sudo -u ansadm -s
ssh-copy-id $HOST
ansible all -a "tail -1 /etc/shadow"
#
ANS_HOME=/home/ws/ansible/$HOST
cd $ANS_HOME
ansible-playbook playbook/i_10_basic.yaml

Tipps[Bearbeiten]

- name: Using dict2items
  ansible.builtin.debug:
    msg: "{{ item.key }} - {{ item.value }}"
  loop: "{{ tag_data | dict2items }}"
  vars:
    tag_data:
      Environment: dev
      Application: payment

- name: Add several users
  ansible.builtin.user:
    name: "{{ item.name }}"
    state: present
    groups: "{{ item.groups }}"
  loop:
    - { name: 'testuser1', groups: 'wheel' }
    - { name: 'testuser2', groups: 'root' }