{"id":20698129,"url":"https://github.com/clouddrove/ansible-commands","last_synced_at":"2025-04-22T21:44:45.763Z","repository":{"id":35843028,"uuid":"161634275","full_name":"clouddrove/ansible-commands","owner":"clouddrove","description":"This repository is used to understand how to use ansible commands.","archived":false,"fork":false,"pushed_at":"2022-06-19T22:25:34.000Z","size":20,"stargazers_count":30,"open_issues_count":0,"forks_count":23,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-15T17:54:49.613Z","etag":null,"topics":["ansible","ansible-commands","cheet-sheet","cheetsheet","clouddrove","devops","playbook","role"],"latest_commit_sha":null,"homepage":"https://ansible.com","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clouddrove.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}},"created_at":"2018-12-13T12:13:24.000Z","updated_at":"2025-04-07T06:38:09.000Z","dependencies_parsed_at":"2022-08-24T05:21:10.491Z","dependency_job_id":null,"html_url":"https://github.com/clouddrove/ansible-commands","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/clouddrove%2Fansible-commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clouddrove%2Fansible-commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clouddrove%2Fansible-commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clouddrove%2Fansible-commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clouddrove","download_url":"https://codeload.github.com/clouddrove/ansible-commands/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250330470,"owners_count":21412985,"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-commands","cheet-sheet","cheetsheet","clouddrove","devops","playbook","role"],"created_at":"2024-11-17T00:22:57.344Z","updated_at":"2025-04-22T21:44:45.737Z","avatar_url":"https://github.com/clouddrove.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://i.imgur.com/xYb2PRb.png\" /\u003e\u003c/p\u003e\n\n\u003e Ansible commands\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"LICENSE.md\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\" alt=\"Software License\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nList of general purpose commands for Ansible management:\n\n## Installation\n\n```bash\nsudo apt-add-repository ppa:ansible/ansible\nsudo apt-get update\nsudo apt-get install ansible\nansible --version\n```\n\n## Inventory\n\nExample of Inventory file\n\n```ini\n[mysql]\n10.0.0.13 = Env=live EcType=mysql EcName=live-mysql-0-b Az=a Nr=0\n[nginx]\n10.0.0.17 = Env=live EcType=nginx EcName=live-nginx-0-b Az=a Nr=0\n\n[live:children]\nmysql\nnginx\n```\n\n## Check Connection\n\n```yaml\n$ ansible -m ping \u003chost\u003e\n```\n\n## Ad-Hoc Commands\n\n#### Parallelism Shell Commands\n\n```bash\nssh-agnet bash $ ssh-add ~/.ssh/id_rsa\n```\n\u003e Reboot remove server using anisble\n```yaml\nansible mysql -a \"/sbin/reboot\" -f 20\n```\n\u003e Run ansible using specific user\n```yaml\nansible nginx -a \"/usr/bin/foo\" -u anmolnagpal\n```\n\u003e Run ansible using specific user\n```yaml\nansible nginx -a \"/usr/bin/foo\" -u anmolnagpal\n```\n#### File Transfer\n\n\u003e Transfer file to many servers\n```yaml\nansible nginx -m copy -a \"src=/etc/anmol.txt dest=/tmp/anmol.txt\"\n```\n\u003e Transfer file with specific ownership \u0026 permission\n```yaml\nansible nginx -m file -a \"src=/etc/anmol.txt dest=/tmp/anmol.txt mode=600\"\nansible nginx -m file -a \"src=/etc/anmol.txt dest=/tmp/anmol.txt mode=600 owner=anmol gorup=anmol\"\n```\n\u003e Create Directories\n```yaml\nansible nginx -m file -a \"dest=/tmp/clouddrove mode=755 owner=anmol gorup=anmol stage=directory\"\n```\n\u003e Delete Directories\n```yaml\nansible nginx -m file -a \"dest=/tmp/clouddrove state=absent\"\n```\n\n#### Manage Packages\n\n\u003e Ensure package is installed, but doesn't get updated\n```yaml\nansible mysql -m apt -a \"name=python state=present\"\n```\n\u003e Ensure package is installed to a specific version\n```yaml\nansible mysql -m apt -a \"name=python-2.6 state=present\"\n```\n\u003e Ensure package is installed with latest version\n```yaml\nansible mysql -m apt -a \"name=python state=latest\"\n```\n\u003e Ensure package is installed is not installed\n```yaml\nansible mysql -m apt -a \"name=python state=absent\"\n```\n\n#### Manage Services\n\n\u003e Ensure a service is started on all nginx servers\n```yaml\nansible nginx -m service -a \"name=nginx state=started\"\n```\n\u003e Restart service on all nginx servers\n```yaml\nansible nginx -m service -a \"name=nginx state=restarted\"\n```\n\u003e Ensure a service is stopped\n```yaml\nansible nginx -m service -a \"name=nginx state=stopped\"\n```\n\n## Playbooks\n\n#### Playbook: Update system (Debian based)\n\n```yaml\n- hosts: local\n  tasks:\n    - name: Update system\n      apt:\n        update_cache: yes\n        upgrade: yes\n    - name: Remove dependencies\n      apt:\n        autoremove: yes\n    - name: Remove useless packages from the cache\n      apt:\n        autoclean: yes\n```\n\n#### Playbook: List Kubernetes Cluster Nodes\n\n```yml\n- name: Kubernetes Cluster Health Check\n  hosts: k8s\n  become: true\n  gather_facts: false\n  tasks:\n    - name: Checking the Kubernetes Nodes\n      shell:\n        kubectl get nodes \n      register: results\n\n    - name: Print the Kubernetes Nodes\n      debug:\n        msg: \"{{ results.stdout.split('\\n') }}\"\n```\n\n#### Sample Playbooks\n\n```yaml\n- name: dpkg --configure -a\n  shell: dpkg --configure -a\n  tags:\n    - dpkg\n\n- name: install system pakcages and utils\n  apt:\n    name: \"{{ item }}\"\n    state: latest\n    update_cache: yes\n    cache_valid_time: 5400\n    allow_unauthenticated: yes\n  with_items:\n   - ntp\n   - git\n   - git-core\n   - htop\n   - vim\n   - curl\n   - unzip\n   - jq\n   - python-setuptools\n   - python-dev\n   - build-essential\n  tags:\n    - packages\n```\n\n#### Writing Playbooks\n\u003e Create a playbook\n```yaml\n- hosts: live-node-01\n  become: true\n  roles:\n    - { role: common,    tags: [ 'common'    ] }\n    - { role: docker,    tags: [ 'docker'    ] }\n    - { role: jenkins,   tags: [ 'agent'     ] }\n    - { role: selenoid,  tags: [ 'selenoid'  ] }\n```\n\n#### Ansible Vault\n\u003e Using the argument “ — ask-vault-pass”\n```\nansible-playbook users.yml --ask-vault-pass\n```\n\u003e Using the argument “ — vault-password-file”\n```\nansible-playbook users.yml --vault-password-file /anmol/.ansible/vault-passwd\n```\n\nMore about Ansible:\n\n- https://docs.ansible.com/ansible/latest/index.html\n- https://medium.com/clouddrove/about-ansible-vault-cbeeae7add87\n- https://medium.com/tech-tajawal/ansible-an-effective-it-automation-tool-be603417ea1a\n\n## 👬 Contribution\n- Open pull request with improvements\n- Discuss ideas in issues\n\n- Reach out with any feedback [![Twitter URL](https://img.shields.io/twitter/url/https/twitter.com/anmol_nagpal.svg?style=social\u0026label=Follow%20%40anmol_nagpal)](https://twitter.com/anmol_nagpal)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclouddrove%2Fansible-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclouddrove%2Fansible-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclouddrove%2Fansible-commands/lists"}