Ansible configuration on remote Nodegrid devices

Ansible configuration on remote Nodegrid devices

Ansible playbook can be used to automate remote devices. Every remote device needs to have one ansible user to apply the automation.
Follow this script to have complete configuration of ansible user, ssh keys, sudo permission on remote Nodegrid device.
Create these four files in one folder and later give them executable permission.

1. ansible_setup.sh 
  1. #!/bin/sh

  2. read -p " Enter Your Choice 1(yes)/2(no): " choice

  3. while [ $choice -eq 1 ]
  4. do
  5. read -p "enter the ip address : " IPADDRESS
  6. echo " The ip address is $IPADDRESS "
  7. echo "Copy all config files to Nodegrid, provide root password"
  8. scp ansible_setup* root@$IPADDRESS:/tmp/
  9. echo "Create Ansible User and Group, provide root password"
  10. ssh root@$IPADDRESS 'su admin -l -c "cli -f /tmp/ansible_setup.cli"'
  11. echo "Create Ansible sudoers file, provide root password"
  12. ssh root@$IPADDRESS '/bin/bash /tmp/ansible_setup_sudoers.sh'
  13. echo "Copy ssh-key to Ansible user, provide ansible password"
  14. ssh-copy-id -i .ssh/id_rsa.pub ansible@$IPADDRESS
  15. echo "Applying the Sudo Permission"
  16. ssh root@$IPADDRESS 'su admin -l -c "cli -f /tmp/ansible_setup_sudop.cli"'
  17. echo "Delete setup files from Nodegrid, provide root password"
  18. ssh root@$IPADDRESS 'rm /tmp/ansible_setup*'
  19. read -p "Enter Your Choice 1(yes)/2(no): " choice
  20. done
2. ansible_setup.cli
  1. cd /settings/authorization/
  2. add
  3. set name=ansible
  4. commit
  5. cd ansible/profile/
  6. set track_system_information=yes
  7. set terminate_sessions=yes
  8. set software_upgrade_and_reboot_system=yes
  9. set configure_system=yes
  10. set configure_user_accounts=yes
  11. set apply_&_save_settings=yes
  12. set shell_access=yes
  13. set restrict_configure_system_permission_to_read_only=no
  14. set menu-driven_access_to_devices=no
  15. set custom_session_timeout=no
  16. set startup_application=shell
  17. commit
  18. cd /settings/local_accounts/
  19. add
  20. set username=ansible
  21. set password=1234
  22. set hash_format_password=no
  23. set user_group=ansible
  24. commit
3. ansible_setup_sudoers.sh
  1. #!/bin/bash
  2. echo "ansible ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/ansible
  3. chmod 600 /etc/sudoers.d/ansible
4. ansible_setup_sudop.cli
  1. set /settings/authorization/ansible/profile/ sudo_permission=yes
  2. commit
Now, run the script : sudo ./ansible_setup.sh
Enter root password for remote nodegrid when asked and ansible password is what one has given in ansible_setup.cli file