{"id":24701765,"url":"https://github.com/hurricanemark/ansible_server_configuration","last_synced_at":"2025-03-22T04:13:24.954Z","repository":{"id":115763658,"uuid":"146985852","full_name":"hurricanemark/ansible_server_configuration","owner":"hurricanemark","description":"Full scenario on configuring ansible to control remote servers (cloud and on premise) of various OS platforms, and different type of credentials.","archived":false,"fork":false,"pushed_at":"2018-09-27T20:55:51.000Z","size":46,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-27T05:27:16.653Z","etag":null,"topics":["ansible","ansible-playbook","automate-tests","cloud-deploymnent","config-server"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hurricanemark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-01T09:35:07.000Z","updated_at":"2019-01-16T05:58:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"bef2bbb7-1074-4492-8e00-0e77c1efbc09","html_url":"https://github.com/hurricanemark/ansible_server_configuration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2Fansible_server_configuration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2Fansible_server_configuration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2Fansible_server_configuration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2Fansible_server_configuration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hurricanemark","download_url":"https://codeload.github.com/hurricanemark/ansible_server_configuration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244902924,"owners_count":20529115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-playbook","automate-tests","cloud-deploymnent","config-server"],"created_at":"2025-01-27T05:25:22.542Z","updated_at":"2025-03-22T04:13:24.942Z","avatar_url":"https://github.com/hurricanemark.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Configure Servers Using Ansible  \n\n\n[__Ansible__](https://en.wikipedia.org/wiki/Ansible) is a server configuration tool.  It is an open source software that automates software provisioning, configuration management, and application deployment. Ansible connects via SSH, remote PowerShell or via other remote APIs. \n\nGenerally, Ansible is used as a main option for deploying software built by Jenkins to test servers.\n\n__This document describes steps used to have Ansible configures and controls three separate OS environments (servers) via the use of SSH.__\n__Once followed through the end, you should have three configured servers and one playbook to rule them all.__\n\nFor the purpose of demonstrating how Ansible is used to configure and provision remote servers via SSH, let's refer to the table below.  We have a local controller node (*ubuntu16*), and three remote nodes (*raspberrypi3*, *linux1rhel*, *azuresles12*).  Note, it is suggested that all nodes have the same user account. e.g. *hurricanemark*.  In the case of different user account, specify it in ~/.ssh/config.\n\n| Ansible Controller | Test Server    | IP_addr       | User          |\n| ------------------ |:---------------| -------------:|---------------|\n| *ubuntu16*         |                | 192.168.0.10  | hurricanemark |\n|                    | *raspberrypi3* | 192.168.0.35  | hurricanemark |\n|                    | *linux1rhel*   | 148.100.99.23 | jakeo         |\n|                    | *azuresles12*  | 13.99.130.110 | hurricanemark |\n \n\n#### Aliases for SSH:\n __Content of *~/.ssh/config* on *ubuntu16*__\n \n\tHost raspberrypi3\n      HostName 192.168.0.35\n      User hurricanemark\n\tHost linux1rhel\n      HostName 148.100.99.23\n      User jakeo\n      IdentityFile ~/.ssh/identity_linux1_priv\n \tHost azuresles12\n      HostName 13.99.130.110\n      User hurricanemark\n\nMake sure to change permission on ~/.ssh/identity_linux1_priv to 400. You can now reference ip address 148.100.99.23 by its alias *linux1rhel*\n\n\u003e hurricanemark@ubuntu16\u003e **ssh linux1rhel**\n\n\n### Connect to servers with openssh\n\u003e hurricanemark@ubuntu16\u003e **ssh-keygen**\n\n\u003e hurricanemark@ubuntu16\u003e **ssh-copy-id hurricanemark@raspberrypi3**\n\n\u003e hurricanemark@ubuntu16\u003e **ssh-copy-id hurricanemark@azuresles12**\n\n\u003e hurricanemark@ubuntu16\u003e **ssh-copy-id -i ~/.ssh/identity_linux1_priv jakeo@linux1rhel**  \n\n### Install ansible on the controller\nThe attraction of this tool is this is the only installation you will need to run Ansible.\n\n\u003e hurricanemark@ubuntu16#  **apt-add-repository ppa:ansible/ansible**\n\n\u003e hurricanemark@ubuntu16# **apt-get update**\n\n\u003e hurricanemark@ubuntu16# **apt install ansible**\n\n\u003e hurricanemark@ubuntu16# **ansible -version**\n\n\n### Create ansible workspace\n1. Create private workspace ( in your home directory).\n\u003e hurricanemark@ubuntu16\u003e **cp -R /etc/ansible ~/myansible**\n\n\u003e hurricanemark@ubuntu16\u003e **vi ~/myansible/ansible.cfg**\n\nModify this line\n\n\t\tinventory\t= hosts\n    \n\u003e hurricanemark@ubuntu16\u003e **vi hosts**\n\nReplace content with\n\n\traspberrypi3\n        azuresles12\n        linux1rhel\n\n\n2. Customize basic tasks pertain to common requirements to your automate server operation.\n   We create separate main.yml according to OS platform differences.  For each main.yml, we define task to install python3.\n\n\n* Create basic common tasks for __Ubuntu__ platforms\n\u003e hurricanemark@ubuntu16\u003e **mkdir -p ~/myansible/roles/basic4ubuntu/tasks**\n\n\u003e hurricanemark@ubuntu16\u003e **vi ~/myansible/roles/basic4ubuntu/tasks/main.yml**\n\n\n\t\t- name: \"Installing python3\"\n    \t   apt: pkg=python3 state=present\n        \n* Create basic common tasks for __RHEL__ platforms\n\u003e hurricanemark@ubuntu16\u003e **mkdir -p ~/myansible/roles/basic4rhel/tasks**\n\n\u003e hurricanemark@ubuntu16\u003e **vi ~/myansible/roles/basic4rhel/tasks/main.yml**\n\n\n\t\t- name: \"Installing python3\"\n    \t   yum: pkg=python3 state=present\n        \n        \n* Create basic common tasks for __SLES__ platforms\n\u003e hurricanemark@ubuntu16\u003e **mkdir -p ~/myansible/roles/basic4sles/tasks**\n\n\u003e hurricanemark@ubuntu16\u003e **vi ~/myansible/roles/basic4sles/tasks/main.yml**\n\n\n\t\t- name: \"Installing python3\"\n    \t  zypper: pkg=python3 state=present\n\n\n\n* Create ansible playbook for controller node\n\u003e hurricanemark@ubuntu16\u003e **vi ~/myansible/playbook.yml**\n\n\n\t\t---\n        - hosts: raspberrypi3\n        \tbecome: true\n            roles:\n            \t- basic4ubuntu\n                \n        - hosts: linux1rhel\n        \tbecome: true\n            roles:\n            \t- basic4rhel\n                \n        - hosts: azuresles12\n        \tbecome: true\n            roles:\n            \t- basic4sles\n                \n\n\n\n### Ansible Ad-hoc commands\n\nLet's test the interconnectivity we have set up thus far.\n\u003e hurricanemark@ubuntu16\u003e **ansible -version**\n\n\u003e hurricanemark@ubuntu16\u003e **ansible -m shell -a 'whoami' all**\n\n\u003e hurricanemark@ubuntu16\u003e **ansible -m shell -a 'ping -c1 www.google.com' all**\n\n\u003e hurricanemark@ubuntu16\u003e **ansible -b -K -m user -a 'name=hurricanemark' all**\n\n\nNow, run basic tasks on all three servers.\n\n\u003e hurricanemark@ubuntu16\u003e **ansible-playbook -K ~/myansible/playbook.yml**\n\n\u003e hurricanemark@ubuntu16\u003e **ansible-playbook playbook_aws.yml**\n\n\n## Pain points\n\nWe engineers and developers, would instantly recognize the pain points in doing the above.\nI can name a few: It is labor intensive, no conditional failsafe for diferrences in OS/platform dependencies, etc.  However, we need to learn how to crawl before we can walk.\n\nIn order for an organization to grow, infrastructure as code is a neccessity.  In my future checkin to github repo will address grouping inventory technique in configuring ansible.cfg and hosts\nFurther down the line, checkout Terraform and all of its modules [terraform module registry](https://registry.terraform.io/).\n\n\nHappy DevOps 'ing.  \n \n## References\n[Ansible ad-hoc commands](https://docs.ansible.com/latest/usr_guide/intro_adhoc.html)\n\n[Ben's IT Lesson](https://www.youtube.com/channel/UCLLumGsi1QboyiFIJf8a-0wa)\n\n## Feedback\nhttps://github.com/hurricanemark\n\n[email](\u003ca href=\"emailto:hurricanemark@gmail.com\"\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhurricanemark%2Fansible_server_configuration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhurricanemark%2Fansible_server_configuration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhurricanemark%2Fansible_server_configuration/lists"}