0

I am trying to find a solution (if is possible) to create a python script that pushes a configuration text file (batch of commands ~ 1000s of lines) over ssh.

So far, I have a solution to push few commands, but it doesn't apply when there are 1000s of lines.

2
  • What do you mean, "push"? Are you trying to copy a file? If so why can't you use scp? Commented Oct 28, 2018 at 8:34
  • Remote device is a Huawei switch. By push I mean to deploy all the commands contained in the text file at once. Commented Oct 28, 2018 at 8:39

1 Answer 1

2

Have you heard about Ansible? It does the job you want to do, and it's written mostly in python.

App deployment, configuration management, and orchestration — all from one system. Ansible is simple, agentless automation that anyone can use.

Ansible Documentaion

Long story short you writte playboks (.yaml templates). Simply put, playbooks are the basis for a really simple configuration management and multi-machine deployment system, unlike any that already exist, and one that is very well suited to deploying complex applications.

Example playbook:

---
- hosts: webservers
  vars:
    http_port: 80
    max_clients: 200
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum:
      name: httpd
      state: latest
  - name: write the apache config file
    template:
      src: /srv/httpd.j2
      dest: /etc/httpd.conf
    notify:
    - restart apache
  - name: ensure apache is running
    service:
      name: httpd
      state: started
  handlers:
    - name: restart apache
      service:
        name: httpd
        state: restarted

When you will create playbook that suits your needs just run it against your machine or list of them. There is a huge list of modules available to ansible ready to use. You can also write your own plugins.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.