Working With Variables In Ansible
- Gathering Facts:
- Whenever you ansible against hosts ansible some information as metadata in var which can be later used for efficiently generalizing our playbook
- Lets try to get which information is stored in ansible variable by running
ansible -m setup app1
- Using Ansible gathering facts varible
- We will try to hostname of webserver into a webpage by using ansible variable
- Please make changes in your setup-app.yml file
- Now run your playbook with:
ansible-playbook setup-app.yml
- Using local variable
- Local variable be defined in playbooks itself
- We will use dir variable to defined /var/www/html as a variable and call it whenever needed in playbook
- Please make changes in your setup-app.yml file
- Now run your playbook with:
ansible-playbook setup-app.yml
- Using registered variable
- Create variables from info returned from tasks ran using register
- Call the registered variables for later use
- Use the debug module anytime to see variables and debug our playbooks
- Please make changes in your setup-app.yml file
- Now run your playbook with:
ansible-playbook setup-app.yml