I have been learning and writing Ansible for Cloud automation. Created this code repository to share my Ansible automation learnings as snippets.
As I explore and learn Ansible, I will be adding the simple and easy to use Ansible code snippets written in YAML.
š§ The snippets include generic yaml code for you to understand the Ansible in-built modules and how to use them for your Ansible automation. More code snippets to come. So, ā this repository š
Run locally
- Install and setup Ansible
- Command to run locally on your terminal or command prompt
ansible-playbook list_files.yaml -i hosts.ini --flush-cache
For verbose output, use
-vvvv
flag in the ansible command
Expected output:
PLAY [List files] *****************************************************************************************************************************************************************************
TASK [List files in the current directory] ****************************************************************************************************************************************************
changed: [localhost]
TASK [debug] **********************************************************************************************************************************************************************************
ok: [localhost] => {
"output.stdout_lines": [
"LICENSE",
"README.md",
"add_user_to_os.yaml",
"ansible.cfg",
"curl_requests.yaml",
"hosts.ini",
"list_files.yaml",
"yum_install_dependencies.yaml"
]
}
PLAY RECAP ************************************************************************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- cURL requests: add
--ask-become-pass
flag prompting for a root user password
ansible-playbook curl_requests.yaml -i hosts.ini --flush-cache --ask-become-pass
Expected output:
BECOME password:
PLAY [CURL GET and POST requests] *************************************************************************************************************************************************************
TASK [POST request with JSON and bearer token] ************************************************************************************************************************************************
ok: [localhost]
TASK [Print return information from the previous task] ****************************************************************************************************************************************
ok: [localhost] => {
"result.json": {
"success": "true"
}
}
TASK [GET request to download a file] *********************************************************************************************************************************************************
ok: [localhost]
TASK [debug] **********************************************************************************************************************************************************************************
ok: [localhost] => {
"result": {
"changed": false,
"dest": "./filename.txt",
"elapsed": 0,
"failed": false,
"gid": 0,
"group": "wheel",
"mode": "0644",
"msg": "HTTP Error 304: Not Modified",
"owner": "root",
"size": 10612,
"state": "file",
"status_code": 304,
"uid": 0,
"url": "https://reqbin.com/echo"
}
}
PLAY RECAP ************************************************************************************************************************************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Simple and easy-to-use Ansible code snippets in YAML https://github.com/VidyasagarMSC/ansible-yaml-snippets @ansible @RedHat
Top comments (0)