{"id":22941291,"url":"https://github.com/thejaxon/rhce_env","last_synced_at":"2025-08-12T21:31:48.872Z","repository":{"id":41272220,"uuid":"281628301","full_name":"theJaxon/RHCE_ENV","owner":"theJaxon","description":"An environment made as a preparation for RHCE [ex294] exam","archived":false,"fork":false,"pushed_at":"2020-09-30T13:13:56.000Z","size":29,"stargazers_count":10,"open_issues_count":0,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-03-09T06:41:33.093Z","etag":null,"topics":["ansible","rhce","vagrant"],"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/theJaxon.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}},"created_at":"2020-07-22T09:04:41.000Z","updated_at":"2023-01-30T22:09:48.000Z","dependencies_parsed_at":"2022-09-21T00:01:56.168Z","dependency_job_id":null,"html_url":"https://github.com/theJaxon/RHCE_ENV","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theJaxon%2FRHCE_ENV","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theJaxon%2FRHCE_ENV/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theJaxon%2FRHCE_ENV/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theJaxon%2FRHCE_ENV/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theJaxon","download_url":"https://codeload.github.com/theJaxon/RHCE_ENV/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229709234,"owners_count":18111386,"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","rhce","vagrant"],"created_at":"2024-12-14T13:38:36.462Z","updated_at":"2024-12-14T13:38:37.060Z","avatar_url":"https://github.com/theJaxon.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# RHCE_ENV\nAn environment made as a preparation for RHCE [EX294] exam\n\n---\n\n#### Useful tips:\n1- Gather facts again inside the playbook\n* Can be done using the `setup` module \n\n```yml\n- name: gather facts again\n  setup:\n```\n\n* Can also be done using another play inside that playbook\n```yml\nhosts: localhost\ntasks:\n  - name: install httpd\n    yum:\n      name: httpd\n      state: latest \n\nhosts: localhost # facts are being gathered again\ntasks:\n  - name: gather package facts\n    package_facts:\n      manager: auto\n```\n\n2- Edit ~/.vimrc to allow auto indent\n```bash\nvi ~/.vimrc\nset ai\n```\n\n3- Add `--syntax-check` flag at the end of the command to verify there was no syntax issues, remove it quickly using `ctrl + w`\n```bash\nansible-playbook \u003cname\u003e.yml --syntax-check\n```\n\n---\n\n#### rhel-system-roles:\n```bash\nsudo yum install -y rhel-system-roles\n```\n:file_folder: **Important dirs**:\n* /etc/ansible/\n  * hosts\n  * ansible.cfg\n  * facts.d/ # for storing custom facts (file extension must be .fact)\n\n* /usr/share\n  * /ansible/roles\n  * /doc/rhel-system-roles\n\n---\n\n#### :clock1: Fact caching:\n* Mainly done when managing a large fleet of servers to save the time spent gathering facts at the beginning of the playbook.\n\n1. Caching using redis\n```ini\n[defaults]\ngathering = smart\nfact_caching = redis\nfact_caching_timeout = 7200 # 2 hours timeout\n```\n\n2. Caching locally using a file\n```ini\n[defaults]\ngathering = smart\nfact_caching = jsonfile\nfact_caching_timeout = 7200\nfact_caching_connection = /tmp/fact_cache\n```\n---\n\n#### Ansible Facts:\n* `ansible_local` used to get local facts stored in /etc/ansible/facts.d/\u003cname\u003e.fact\n\n---\n\n#### [Magic Variables](https://docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html):\n1. hostvars # access vars defined for any host in the play\n2. groups # List of all groups in the inventory\n3. group_names # List of groups that the current host is part of\n4. inventory_hostname # same as ansible_hostname\n5. inventory_file \n\n---\n\n#### Quick Tip for `configure managed nodes` objective:\n1- Generate the ssh key on controller node first `ssh-keygen`\n2- Make a shell script that automates the user creation, password and privilege escalation part \n3- use `scp` to place it in /tmp on all the hosts that will be managed \n4- run it then from controller copy ssh key using `ssh-copy-id`\n\n```bash\nuseradd ansible \necho ansible | passwd --stdin ansible \nusermod -aG wheel ansible \necho \"ansible ALL=(ALL) NOPASSWD: ALL\" \u003e /etc/sudoers.d/ansible\n```\n\nList of hosts that will be managed:\n```\n192.168.50.221 ansible1\n192.168.50.222 ansible2\n192.168.50.223 ansible3\n192.168.50.224 ansible4\n```\n\nAn easier approach for achieving same objective is to generate the keys then use `group_vars` and use the `all` group to set `ansible_ssh_password` to the host password \nthen make a playbook that uses `authorized_key` module to place the generated ssh key to the managed hosts\n\n```yml\n- hosts: all\n  tasks:\n    - name: copy authorized keys\n      authorized_key:\n        user: vagrant\n        key: \"{{ lookup('file', '/home/vagrant/.ssh/id_rsa.pub') }}\"\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejaxon%2Frhce_env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthejaxon%2Frhce_env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejaxon%2Frhce_env/lists"}