Development of auto-inventory

This commit is contained in:
Tanguy Herbron 2021-10-16 18:29:06 +02:00
parent dc7d7b905f
commit 960c02f914
5 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,25 @@
from paramiko import SSHClient,AutoAddPolicy
from getpass import getpass
address = input("Machine address: ")
username = input("SSH user: ")
password = getpass()
print("Connecting to", address, "as", username, "...")
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(address, username=username, password=password)
stdin, stdout, stderr = client.exec_command("su")
stdin.write(password + '\n')
stdin.write("touch /home/tanguy/testing\n")
stdin.write("exit\n")
stdin.flush()
print("Return", stdout.read().decode("utf8"))
ret = stdout.channel.recv_exit_status()
stdin.close()
stdout.close()
stderr.close()
client.close()

View File

@ -0,0 +1,3 @@
#!/bin/bash
echo ""

5
setup/testing.yml Normal file
View File

@ -0,0 +1,5 @@
---
- name: Testing tasks
hosts: all
tasks:
- debug: var=ansible_all_ipv4_addresses

14
setup/user_setup.yml Normal file
View File

@ -0,0 +1,14 @@
---
- name: Setup ansible configuration for new host
hosts: all
tasks:
- name: Add 'ansible' system user and setup SSH key
become: yes
user:
name: ansible
comment: Automation user for ansible
system: True
create_home: False
generate_ssh_key: yes
ssh_key_bits: 4096
ssh_key_file: /etc/ansible/.id_rsa

1
tmp_hosts Normal file
View File

@ -0,0 +1 @@
10.10.0.23