Development of auto-inventory
This commit is contained in:
parent
dc7d7b905f
commit
960c02f914
25
setup/inventory_builder.py
Normal file
25
setup/inventory_builder.py
Normal 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()
|
3
setup/inventory_builder.sh
Normal file
3
setup/inventory_builder.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo ""
|
5
setup/testing.yml
Normal file
5
setup/testing.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Testing tasks
|
||||||
|
hosts: all
|
||||||
|
tasks:
|
||||||
|
- debug: var=ansible_all_ipv4_addresses
|
14
setup/user_setup.yml
Normal file
14
setup/user_setup.yml
Normal 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
|
Loading…
Reference in New Issue
Block a user