{"id":22744148,"url":"https://github.com/mehradi-github/ref-ansible","last_synced_at":"2026-05-15T20:32:33.265Z","repository":{"id":144808704,"uuid":"548754059","full_name":"mehradi-github/ref-ansible","owner":"mehradi-github","description":"Automation with Ansible.","archived":false,"fork":false,"pushed_at":"2023-05-28T17:38:34.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-07T01:07:12.490Z","etag":null,"topics":["ansible","ansible-playbook","automation","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mehradi-github.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2022-10-10T06:07:34.000Z","updated_at":"2023-05-27T22:26:30.000Z","dependencies_parsed_at":"2023-06-29T06:45:46.382Z","dependency_job_id":null,"html_url":"https://github.com/mehradi-github/ref-ansible","commit_stats":null,"previous_names":["mehradi-github/ref-ansible"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mehradi-github/ref-ansible","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehradi-github%2Fref-ansible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehradi-github%2Fref-ansible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehradi-github%2Fref-ansible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehradi-github%2Fref-ansible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehradi-github","download_url":"https://codeload.github.com/mehradi-github/ref-ansible/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehradi-github%2Fref-ansible/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33078899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","automation","python"],"created_at":"2024-12-11T01:40:10.496Z","updated_at":"2026-05-15T20:32:33.260Z","avatar_url":"https://github.com/mehradi-github.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Automation with Ansible\n\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n## Table of Contents\n- [Automation with Ansible](#automation-with-ansible)\n  - [Table of Contents](#table-of-contents)\n  - [What is Ansible?](#what-is-ansible)\n  - [Installing Ansible](#installing-ansible)\n    - [Installing Ansible from PyPI using pip](#installing-ansible-from-pypi-using-pip)\n    - [Installing Ansible on specific operating systems](#installing-ansible-on-specific-operating-systems)\n      - [Installing Ansible on Ubuntu](#installing-ansible-on-ubuntu)\n      - [Installing Ansible on Amazon Linux 2](#installing-ansible-on-amazon-linux-2)\n  - [Ansible playbooks](#ansible-playbooks)\n    - [Handlers: running operations on change](#handlers-running-operations-on-change)\n    - [Notifying handlers](#notifying-handlers)\n    - [Loops](#loops)\n    - [Import a task list](#import-a-task-list)\n    - [Delegating tasks](#delegating-tasks)\n    - [Template](#template)\n    - [Vault](#vault)\n    - [Roles](#roles)\n\n## What is Ansible?\n[Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) automates the management of remote systems and controls their desired state.A basic Ansible environment has three main components:\n- **Control node:**\nA system on which Ansible is installed. You run Ansible commands such as ansible or ansible-inventory on a control node.\n\n- **Managed node:**\nA remote system, or host, that Ansible controls.\n\n- **Inventory:**\nA list of managed nodes that are logically organized. You create an inventory on the control node to describe host deployments to Ansible. \n\n\u003cimg src=\"public/assets/images/ansible_basic.svg\" alt=\"Basic components of an Ansible environment include a control node, an inventory of managed nodes, and a module copied to each managed node.\" width=\"266\" height=\"321\"\u003e\n\n\n## Installing Ansible \n### Installing Ansible from PyPI using pip\nThe ansible package can always be installed from PyPI [using pip](https://github.com/mehradi-github/ref-python#installing-packages-using-pip) on most systems but it is also packaged and maintained by the community for a variety of Linux distributions. [more detailes](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#intro-installation-guide).\n\n### Installing Ansible on specific operating systems\nInstalling Ansible on specific operating systems: [Fedora, CentOS, Debian, Ubuntu, Windows](https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html)\n\n#### Installing Ansible on Ubuntu\n```sh\nsudo apt update\nsudo apt install software-properties-common\nsudo add-apt-repository --yes --update ppa:ansible/ansible\nsudo apt install ansible\n```\n\n#### Installing Ansible on Amazon Linux 2\n```sh\n\npython -V\n\n#Install python and python-pip\nsudo yum -y update\nsudo yum install -y amazon-linux-extras\namazon-linux-extras | grep -i python\nsudo amazon-linux-extras enable python3.8\nsudo yum install python3.8\npython3.8 --version\n\n\n\n#Install from source\nsudo yum -y update\nsudo yum -y groupinstall \"Development Tools\"\nsudo yum -y install openssl-devel bzip2-devel libffi-devel\n\nsudo yum -y install wget\nwget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tg\n\ntar xvf Python-3.8.12.tgz\ncd Python-3.8*/\n./configure --enable-optimizations\nsudo make altinstall\n\n\n\n#Setting Default Python\nsudo alternatives --install /usr/bin/python python /usr/bin/python3.8 1\nsudo alternatives --install /usr/bin/python python /usr/bin/python2.7 2\n\n#Confirm the new setting.\nsudo alternatives --list | grep -i python\nsudo alternatives --config python\n#Ensuring pip is available\npython -m pip -V\n\n#If you see an error like No module named pip\ncurl https://bootstrap.pypa.io/get-pip.py -o get-pip.py\npython get-pip.py --user\n\n\n#Install ansible using pip check for version\npython -m pip install  --user ansible\nansible --version\nwhich ansible\npython -m pip show ansible\n\n#Create a user called ansadmin \u0026 grant sudo access to ansadmin user using \"visudo\" command (on Control node and Managed host)\nuseradd ansadmin\npasswd ansadmin\necho \"ansadmin ALL=(ALL) NOPASSWD: ALL\" \u003e\u003e /etc/sudoers\n\n#Make sure that PasswordAuthentication yes in all servers under /etc/ssh/sshd_config file.\nvi /etc/ssh/sshd_config \nsudo systemctl restart sshd\n\n#Log in as a ansadmin user on master and generate ssh key (on Control node)\nsudo su - ansadmin\nssh-keygen\n#Copy keys onto all ansible managed hosts (on Control node)\nssh-copy-id ansadmin@\u003ctarget-server\u003e\n\n#Validation test\n# Create a directory /etc/ansible and create an inventory file called \"hosts\" add control node and managed hosts IP addresses to it.\nvi /etc/ansible/hosts\nansible all -m ping\n#Gathers facts about remote hosts\nansible all -m setup\n\n```\n\nMore details: [Indexes of all modules and plugins](https://docs.ansible.com/ansible/latest/collections/all_plugins.html)\n\n## Ansible playbooks\nSome of important commands:\n\n```sh\nwhich ansible-playbook\n# Generating ansible.cfg\nansible-config init --disabled \u003e ansible.cfg\nansible-config init --disabled -t all \u003e ansible.cfg\n\nsudo chmod +x sample-playbook.yml\n#!~/.local/bin/ansible-playbook\n./sample-playbook.yml \n\n# --check Dry Run\nansible-playbook sample-playbook.yml -e \"y=2\" --check\n# --extra-var via json\n\necho \"{'y':36}\" \u003e\u003e vars.json\nansible-playbook sample-playbook.yml -e \"@vars.json\" --check\n\n# -k, --ask-pass: ask for connection password\n# -K, --ask-become-pass: ask for privilege escalation password\nansible-playbook sample-playbook.yml -e \"{'y':2,'firstname':'alex'}\" --check\n\n#tags\nansible-playbook tag-playbook.yml -t common\nansible-playbook tag-playbook.yml --tags first,second\nansible-playbook tag-playbook.yml --tags --list-tags\n\n```\nMore Details: [List Filters](https://docs.ansible.com/ansible/2.8/user_guide/playbooks_filters.html#list-filters)\n### Handlers: running operations on change\nSometimes you want a task to run only when a change is made on a machine. For example, you may want to restart a service if a task updates the configuration of that service, but not if the configuration is unchanged. Ansible uses **[handlers](https://docs.ansible.com/ansible/latest/user_guide/playbooks_handlers.html)** to address this use case. Handlers are tasks that only run when notified.\n\n### Notifying handlers\nTasks can instruct one or more handlers to execute using the notify keyword. The notify keyword can be applied to a task and accepts a list of handler names that are notified on a task change. Alternately, a string containing a single handler name can be supplied as well. The following example demonstrates how multiple handlers can be notified by a single task:\n### Loops\nAnsible offers the **[loop](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html)**, with_\u003clookup\u003e, and until keywords to execute a task multiple times.\n\n### Import a task list\n  - [ansible.builtin.import_tasks](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_tasks_module.html) module – Import a task list\n  - [ansible.builtin.include_tasks](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/include_tasks_module.html) module – Dynamically include a task list\n\n### Delegating tasks\nIf you want to perform a task on one host with reference to other hosts, use the [delegate_to](https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html) keyword on a task.\nThere is also a shorthand syntax that you can use on a per-task basis: **local_action**. Using the shorthand syntax for delegating to 127.0.0.1\n\n**run_once:** boolean that will bypass the host loop, forcing the task to attempt to execute on the first host available and afterwards apply any results and facts to all active hosts in the same batch.\n\n### Template\n[ansible.builtin.template](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html) module – [Template](https://jinja.palletsprojects.com/en/3.1.x/) a file out to a target host\n\n\n### Vault\nAnsible Vault encrypts variables and files so you can protect sensitive content such as passwords or keys rather than leaving it visible as plaintext in playbooks or roles. To use Ansible Vault you need one or more passwords to encrypt and decrypt content. If you store your vault passwords in a third-party tool such as a secret manager, you need a script to access them. Use the passwords with the [ansible-vault](https://docs.ansible.com/ansible/latest/user_guide/vault.html) command-line tool to create and view encrypted variables, create encrypted files, encrypt existing files, or edit, re-key, or decrypt files. You can then place encrypted content under source control and share it more safely.\n\n```sh\nansible-vault -h\nansible-vault create keys.yml\nansible-vault view keys.yml\nansible-vault edit keys.yml\nansible-vault rekey keys.yml\n\nansible-playbook vault-playbook.yml  --ask-vault-pass\nansible-playbook vault-playbook.yml  --vault-password-file mypass\nansible-playbook vault-playbook.yml  --vault-id mypass\n# ANSIBLE_VAULT_PASSWORD_FILE=~/.vault_pass.txt\n\n```\n### Roles\n[Roles](https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html) let you automatically load related vars, files, tasks, handlers, and other Ansible artifacts based on a known file structure. After you group your content in roles, you can easily reuse them and share them with other users.\n\nUsing the [ansible-galaxy](https://galaxy.ansible.com/docs/contributing/creating_role.html#creating-roles) command line tool that comes bundled with Ansible, you can create a role with the init command. \n\n```sh\nwhich ansible-galaxy\nansible-galaxy init test-role-1 --offline\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehradi-github%2Fref-ansible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehradi-github%2Fref-ansible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehradi-github%2Fref-ansible/lists"}