added examples

Signed-off-by: Marc Ahlgrim <marc@onemarcfifty.com>
This commit is contained in:
Marc Ahlgrim
2022-09-01 08:41:26 +02:00
parent ba4a5fac73
commit 36dddd6f03
10 changed files with 259 additions and 1 deletions
+61
View File
@@ -0,0 +1,61 @@
---
# ##############################################
# this is a playbook I use in order to deploy
# ansible to target nodes.
# ##############################################
# ##############################################
# first we use a raw ssh connection in order to
# install python3
# so that we can use ansible modules for the
# next steps
# ##############################################
- name: make sure python is installed
hosts: all
gather_facts: false
become: false
tasks:
- name: Install python3
raw: "apt update && apt install python3"
# ##############################################
# Now we can - still as root or whatever user
# we use for the first connection - do the
# following tasks with ansible already.
# the variables for this are defined in rundeck.
# ##############################################
- name: set up user and ssh environment
hosts: all
gather_facts: false
become: true
tasks:
- name: Install sudo apt on debianish hosts
apt:
name: sudo
update_cache: yes
# when: "'debian' in group_names"
- name: Add a new user named ansiblessh
user:
name=ansiblessh
password={{ ansiblessh_password }}
- name: Add ansiblessh user to the sudoers
copy:
dest: "/etc/sudoers.d/ansiblessh"
content: "ansiblessh ALL=(ALL) NOPASSWD: ALL"
- name: Deploy SSH Key
authorized_key: user=ansiblessh
key="{{ lookup('id_rsa', '/var/lib/rundeck/.ssh') }}"
state=present
+42
View File
@@ -0,0 +1,42 @@
---
# ##############################################
# this is a playbook I use in order to lock down
# ssh access, i.e. disable root login and
# force ssh key usage for everyone else
# ##############################################
- name: disable password auth
hosts: all
become: true
gather_facts: false
tasks:
- name: Disable Password Authentication
lineinfile:
dest=/etc/ssh/sshd_config
regexp='^PasswordAuthentication'
line="PasswordAuthentication no"
state=present
backup=yes
notify:
- restart ssh
- name: Disable Root Login
lineinfile:
dest=/etc/ssh/sshd_config
regexp='^PermitRootLogin'
line="PermitRootLogin no"
state=present
backup=yes
notify:
- restart ssh
handlers:
- name: restart ssh
service:
name=sshd
state=restarted
@@ -0,0 +1,33 @@
---
# ##############################################
# Show ansible facts
# ##############################################
# ##########################
- name: show facts
hosts: all:!Windows
gather_facts: true
become: true
# ##########################
tasks:
- name: Print all available facts
ansible.builtin.debug:
# var: ansible_facts
msg: "{{ ansible_facts | dict2items | selectattr('value.macaddress', 'defined') | map(attribute='value') | list }}"
# ##########################
- name: show facts
hosts: Windows
gather_facts: true
become: false
# ##########################
tasks:
- name: Print all available facts
ansible.builtin.debug:
var: ansible_facts.interfaces
+31
View File
@@ -0,0 +1,31 @@
---
# ##############################################
# Some samples how to use ansible on Windows
# targets see here for documentation:
# https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html
# ##############################################
- name: Some Windows Tests
hosts: all
become: false
gather_facts: true
tasks:
- name: send message to users
win_msg:
msg: "hello from Ansible !"
update_cache: yes
- name: Print all available facts
ansible.builtin.debug:
var: ansible_facts
- name: Speech Test
win_say:
start_sound_path: C:\Windows\Media\Windows Balloon.wav
msg: "Nur ein Test für die Sprachausgabe"
end_sound_path: C:\Windows\Media\chimes.wav
- name: Get whoami information
win_whoami: