{"id":24708105,"url":"https://github.com/pungrumpy/ansible-beginning","last_synced_at":"2026-05-19T19:34:03.128Z","repository":{"id":155222534,"uuid":"632563291","full_name":"PunGrumpy/Ansible-Beginning","owner":"PunGrumpy","description":"Learn Ansible Basics ","archived":false,"fork":false,"pushed_at":"2023-04-25T17:05:32.000Z","size":2,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T06:32:17.327Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/PunGrumpy.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":"2023-04-25T17:05:03.000Z","updated_at":"2023-04-25T17:05:48.000Z","dependencies_parsed_at":"2023-05-24T12:00:26.896Z","dependency_job_id":null,"html_url":"https://github.com/PunGrumpy/Ansible-Beginning","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/PunGrumpy%2FAnsible-Beginning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PunGrumpy%2FAnsible-Beginning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PunGrumpy%2FAnsible-Beginning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PunGrumpy%2FAnsible-Beginning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PunGrumpy","download_url":"https://codeload.github.com/PunGrumpy/Ansible-Beginning/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244913330,"owners_count":20530817,"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":[],"created_at":"2025-01-27T06:27:46.963Z","updated_at":"2026-05-19T19:33:58.089Z","avatar_url":"https://github.com/PunGrumpy.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ansible Beginner\n\n- [Resource PDF](https://kodekloud.com/wp-content/uploads/2021/11/ansible-for-beginners-for-pdf.pdf)\n\n## Why Ansinle?\n\n- Provisioning\n- Configuration Management\n- Continuous Delivery (CD)\n- Application Deployment\n- Security Compliance\n\n## Scripts VS Ansible\n\n- Scripts\n  - Time\n  - Coding skill\n  - Maintenance\n- Ansible\n  - Simple\n  - Powerful\n  - Agentless\n\n## What is YAML?\n\n- YAML Ain't Markup Language\n- YAML is a human friendly data serialization standard for all programming languages\n- YAML is a superset of JSON\n- YAML is a superset of XML\n- YAML is a superset of INI\n\n```yaml\n---\n- name: Install Apache\n  hosts: web\n  become: yes\n  tasks:\n    - name: Install Apache\n      yum:\n        name: httpd\n        state: present\n    - name: Start Apache\n      service:\n        name: httpd\n        state: started\n```\n\n### Key value pair\n\n```yaml\nFruit: Apple\nVegetable: Carrot\nMeat: Beef\n```\n\n### Array/List\n\n```yaml\nFruit:\n  - Apple\n  - Orange\n  - Banana\nVegetable:\n  - Carrot\n  - Potato\n  - Tomato\nMeat:\n  - Beef\n  - Chicken\n  - Pork\n```\n\n### Dictionary\n\n```yaml\nFruit:\n  Apple:\n    Color: Red\n    Price: 1.99\n  Orange:\n    Color: Orange\n    Price: 2.99\n  Banana:\n    Color: Yellow\n    Price: 0.99\nVegetable:\n  Carrot:\n    Color: Orange\n    Price: 0.99\n  Potato:\n    Color: Brown\n    Price: 0.99\n  Tomato:\n    Color: Red\n    Price: 0.99\n```\n\n### Notes\n\n- Dictionary - Unordered\n- Array/List - Ordered\n\n## Playbook\n\n- Playbook is a file containing one or more plays\n- Playbook is written in YAML format\n- Playbook is the starting point of any automation\n- Playbook contains plays\n- Playbook is executed using the ansible-playbook command\n\n```yaml\n# playbook.yml\n---\n- name: Install Apache\n  hosts: web\n  become: yes\n  tasks:\n    - name: Install Apache\n      yum:\n        name: httpd\n        state: present\n    - name: Start Apache\n      service:\n        name: httpd\n        state: started\n```\n\n```bash\nansible-playbook playbook.yml\n```\n\n## Ansible Inventory\n\n- Ansible inventory is a file that contains the list of managed nodes\n\n```bash\n# /etc/ansible/hosts\n[web]\nweb1\nweb2\n\n[db]\ndb1\n\n[servers:children]\nweb\ndb\n```\n\n## Ansible Modules\n\n- System modules\n- Commands modules\n- Files modules\n- Database modules\n- Cloud modules\n- Windows modules\n- More...\n\n```yaml\n# playbook.yml\n---\n- name: Install Apache\n  hosts: web\n  become: yes\n  tasks:\n    - name: Install Apache\n      yum:\n        name: httpd\n        state: present\n    - name: Start Apache\n      service:\n        name: httpd\n        state: started # started, restarted, reloaded or stopped\n    - name: Create index.html\n      copy:\n        content: '\u003ch1\u003eHello World\u003c/h1\u003e'\n        dest: /var/www/html/index.html\n    - name: Create ssl directory\n      file:\n        path: /etc/ssl/certs\n        state: directory\n```\n\n## Ansible Variables\n\nStores information that varies with each host\n\n```yaml\n# Inventory\nWeb1 ansible_host=server1.example.com ansible_user=ansible ansible_password=ansible\ndb ansible_host=server2.example.com ansible_user=ansible ansible_password=ansible\n```\n\n```yaml\n# playbook.yml\n---\n- name: Install Apache\n  hosts: web\n  become: yes\n  vars:\n    http_port: '{{ http_port }}'\n    max_clients: '{{ max_clients }}'\n  tasks:\n    - name: Install Apache\n      yum:\n        name: httpd\n        state: present\n    - lineinfile:\n        path: /etc/httpd/conf/httpd.conf\n        regexp: '^Listen'\n        line: 'Listen {{ http_port }}' # {{ http_port }} is a variable\n---\n- name: Install SQL\n  hosts: db\n  become: yes\n  vars:\n    http_port: '{{ http_port }}'\n    max_clients: '{{ max_clients }}'\n  tasks:\n    - name: Install SQL\n      yum:\n        name: mariadb-server\n        state: present\n```\n\n```yaml\n# Variables\nhttp_port: 80\nmax_clients: 200\n```\n\n## Ansible Conditionals\n\n```yaml\n# playbook.yml\n---\n- name: Install NGINX\n  hosts: all\n  tasks:\n    - name: Install NGINX on RedHat\n      yum:\n        name: nginx\n        state: present\n      when: ansible_os_family == 'RedHat'\n    - name: Install NGINX on Debian\n      apt:\n        name: nginx\n        state: present\n      when: ansible_os_family == 'Debian'\n```\n\n### Conditionals in Loops\n\n```yaml\n# playbook.yml\n---\n- name: Install NGINX\n  hosts: all\n  vars:\n    packages:\n      - name: nginx\n        required: yes\n      - name: httpd\n        required: no\n      - name: mysql\n        required: yes\n      - name: apache\n        required: yes\n  tasks:\n    - name: Install \"{{ item.name }}\" package on Debian\n      apt:\n        name: '{{ item.name }}'\n        state: present\n      when: ansible_os_family == 'Debian' and item.required == 'yes'\n      loop: '{{ packages }}'\n```\n\n### Conditionals and Register\n\n```yaml\n# playbook.yml\n---\n- name: Check status of a service and email if its down\n  hosts: all\n  tasks:\n    - name: Check status of a service\n      shell: systemctl httpd status\n      register: result\n    - name: Email if service is down\n      mail:\n        to: admin@example.server\n        subject: Service is Alert\n        body: Httpd Service is down\n      when: result.stdout.find('down') != -1\n```\n\n## Ansible Loop\n\n```yaml\n# playbook.yml\n---\n- name: Create users\n  hosts: all\n  tasks:\n    - user: name= '{{ item.name }}' uid= '{{ item.uid }}' state= present\n      loop:\n        - name: user1\n          uid: 1001\n        - name: user2\n          uid: 1002\n        - name: user3\n          uid: 1003\n```\n\n```yaml\n# playbook.yml\n---\n- name: Create users\n  hosts: all\n  tasks:\n    - user: name= '{{ item }} state= present\n      with_items: # with_file, with_url, with_mongodb\n        - user1\n        - user2\n        - user3\n```\n\n## Ansible Roles\n\n- Roles are the recommended way for structuring your Ansible content\n- Roles are a set of Ansible tasks, handlers, templates, files, variables, and other Ansible components\n- Roles are used to organize and structure your Ansible content\n\n```bash\n# Create a role\nansible-galaxy init role_name # (geerlingguy.apache)\n# Install a role\nansible-galaxy install geerlingguy.apache\n```\n\n```yaml\n# playbook.yml\n---\n- name: Install Apache\n  hosts: web\n  become: yes\n  roles:\n    - geerlingguy.apache\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpungrumpy%2Fansible-beginning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpungrumpy%2Fansible-beginning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpungrumpy%2Fansible-beginning/lists"}