G'day everyone, if you're currently learning Ansible and want to see how all these modules fit together to build something useful, please consider checking out my course and letting me know what you think! It's currently in "early access" while I finish off the last chapter, and the first part of the course is free so you can try it out: learn.toptechskills.com/courses/productive-with-ansible. Thanks for all your support and happy coding!
@sf29983 жыл бұрын
man u have the best ansible tutorials. you should try to create videos to cover every topic of ansible
@toptechskills3 жыл бұрын
Thanks a lot for this comment, it means a lot to me 🙏
@yogienathan80574 жыл бұрын
Super useful and comprehensible. Good work Percy. Glad i found this video.
@toptechskills4 жыл бұрын
Thanks for your kind comment yogie nathan, very happy that you found this video useful. Good luck with Ansible!
@arunkarnad45224 жыл бұрын
Small crisp and informative video
@LuisMiguelZapata4 жыл бұрын
Amazing thank you. Excellent work... smooth and straight to the point. I hope to see more vídeos like this in your channel.
@toptechskills4 жыл бұрын
Thank you so much for your kind comment Luis 🙏
@sukeshnambiar38682 жыл бұрын
Thank you so much. Very helpful.
@toptechskills2 жыл бұрын
You're welcome, thank you for your comment
@flymoracer2 жыл бұрын
Great content, thank you. I have a use case that's slightly more complex, wondering if the template module can help. I'd like to manage the content within a specific section of a configuration file on my Linux servers. Is it possible to search for a specific location within an existing text file and inject a few lines?
@toptechskills Жыл бұрын
The blockinfile module should be what you need: docs.ansible.com/ansible/latest/collections/ansible/builtin/blockinfile_module.html#ansible-collections-ansible-builtin-blockinfile-module
@karthickbaskar68865 жыл бұрын
Superb explanation, easily understandable and very clear in teaching. Keep it up.
@toptechskills5 жыл бұрын
Thank you for all your comments, Karthick 🙏
@alabalistic3 жыл бұрын
Hi, great video quality. June 2021 I try to follow your steps, on Ubuntu 20.04, and I had fail. After changing ansible_user to ansible_user_id. I achieved the goal
@toptechskills3 жыл бұрын
Thank you for the update! I hope this is useful for others who try to follow the video.
@umangverma45575 жыл бұрын
Thanks, Thats a good start Intro to Jinja2
@toptechskills5 жыл бұрын
Thanks for your comment Umang, I'm happy it was a good intro for you.
@amichubby12 жыл бұрын
Wonderful video. Thanks bro..
@toptechskills2 жыл бұрын
You're welcome, thanks a lot for your comment
@sivareddy95342 жыл бұрын
Thanks for the video! I have one question on what is difference between blockinfile and template in Ansible ? I have parameters defined in Jenkins to store some user information from Jenkins and store in meta file - Is there any better way to capture data from user in Ansible other than block file?? Thanks
@toptechskills2 жыл бұрын
`blockinfile` "adds" or "updates" a block of text in a file, whereas `template` completely replaces a file with the templated file. Personally I think it's better to use `template` in all cases, since it's easier to reason about (you can know what the file contents will be by looking at the source code). > Is there any better way to capture data from user in Ansible other than block file?? I'm not sure what you mean by "capture" here, can you clarify?
@RA_I_AM2 жыл бұрын
Clear and to the point
@ramakrishna-pt8ne5 жыл бұрын
Straight to the point ... Thank you!!!!
@Raj-si5yz4 жыл бұрын
Thank you so much,could you give idea how to create Dev,stage and production enviorment?
@toptechskills4 жыл бұрын
Hi Raj, the best way of handling multiple environments is to use groups and then apply different variables to each env using Ansible's `group_vars`. Your roles and playbooks should be the same for all envs, only the values of the variables should change. Here's a good guide from the Ansible docs: docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html#how-to-differentiate-staging-vs-production Here's an excellent guide from DigitalOcean on a similar topic: www.digitalocean.com/community/tutorials/how-to-manage-multistage-environments-with-ansible Hope this helps for now
@vinnyn22494 жыл бұрын
Thanks for the video! Amazing content! I've a question - not related to template module. I've a use case of using Ansible to call a REST Api render it in JSON and then extract data from one much needed object out of the data rendered. Just getting started with Ansible. I was thinking I could use the shell module to curl the api in JSON and extract that one object from JSON using JSON parsor. What do you think? Your comment would be appreciated.
@toptechskills4 жыл бұрын
Hi Vinny, thank you for your comment. I think the `uri` module would be best for your use case: docs.ansible.com/ansible/latest/modules/uri_module.html#uri-module. You will probably need to make use of the `return_content` option, which can parse the JSON response automatically. Here's a snippet to get you started: ``` - name: Make a JSON REST request uri: url: your.jira.example.com/rest/api/2/issue/ method: POST user: your_username password: your_pass body: "{{ lookup('file','issue.json') }}" force_basic_auth: yes status_code: 201 body_format: json return_content: yes register: uri_result - name: Print uri_result debug: var: uri_result ``` Hope that helps, good luck!
@Mrnw103 жыл бұрын
Awesome stuff Percy .. new subscriber incoming!
@toptechskills3 жыл бұрын
Thank you very much 🙏
@Zak0nline4 жыл бұрын
very very good tutorial. thanks for sharing it with us. xD
@toptechskills4 жыл бұрын
Thank you Ben 🙏
@ketanthombare939211 ай бұрын
really really usefull tutorial
@tsivanathan3 жыл бұрын
perfect and thanks a lot!
@toptechskills3 жыл бұрын
You're welcome, thank you for your comment 🙏
@yashasvidevang15333 жыл бұрын
Could you please let me know about PsExec module I tried with some .exe file. But the playbook sticks in the middle. Will not proceed further at all. I waited for 30+ mins. Still the same
@toptechskills3 жыл бұрын
Sorry, I haven't worked with the PsExec module so I can't provide any assistance here. Maybe someone else can help in the comments.
@GGoblin4 жыл бұрын
If you have the time. I get one error stating: "fatal: [dnsserver]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dnsserver' is undefined"}" my dnsserver is the variable of my machine. The weird part is that the rest of my playbook is running smoothly (the playbook itself doesn't contain vars either). Now i did this for replacing an nginx configuration file. I'm not including the code because it's almost identical to yours. Do you know where I should look for this problem. Never engaged this before. Thanks beforehand and great video :-)
@toptechskills4 жыл бұрын
Hi G Goblin, happy to help, do you have a code snippet or something I can look at? Where have you defined the variable `dnsserver`, and where is it used?
@GGoblin4 жыл бұрын
@@toptechskills Well 'dnsserver' is a host machine which the my 'ansibleController' is pushing configuration onto. This is all done with vagrant with multiple vm's. For now I'm only defining dnsserver (no dns-sofware yet). my hosts (defined in hosts.yml): #code snippet from hosts (/etc/ansible/hosts) [servers] dnsserver ansible_host=192.172.1.3 ansible_port=22 ## [webservers] ## alpha.example.org ## beta.example.org ## 192.168.1.100 ## 192.168.1.110 the section in the playbook that goes wrong (defined in /etc/ansible/hosts.yml): - name: kopier nginx config file template: src: nginx.conf.j2 dest: /etc/nignx/nginx.conf the complete error message: fatal: [dnsserver]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dnsserver' is undefined"} Like I said the other plays in the playbook run smoothly and they are no variables declared. thanks in advance!
@GGoblin4 жыл бұрын
@@toptechskills I also see I get the same error when i try to copy files to the destination machine with the ansible copy keyword.
@GGoblin4 жыл бұрын
@@toptechskills If found the error :( apparantly i used an undefined variable in my template file itself so i guess I'll fix it from here. thanks for the reponse though!
@toptechskills4 жыл бұрын
Yeah, if your `dnsserver` is just the name of one of the hosts, it won't be defined as a variable anywhere, but you can use the name to access variables about it by using `hostvars`. If you want to access variables defined on `dnsserver` you can use `hostvars['dnsserver'][...]`. You can check what's available for that host like this: ``` - name: print host vars for dnsserver debug: var=hostvars['dnsserver'] ``` Hope that helps, good luck!
@mandarsalunkhe89494 жыл бұрын
can you use regex under the loop keyword for multiple files? in your case - my_app* (something like this) ? or the loop keyword does not allow that?
@toptechskills4 жыл бұрын
Hi Mandar, you might be looking for something like the `fileglob` plugin: docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html. Let me know if this works for your use case. Thanks for your comment.
@mandarsalunkhe89494 жыл бұрын
Yes that's what I was looking for, thanks!
@JackReacher13 жыл бұрын
so basically using jinja templates have use only if you have different types of host otherwise it is of no use as one can just copy the conf files. does sourcing a conf file in the terminal containing password considered a bad security practice or is it alright in production?
@toptechskills3 жыл бұрын
That's right, if there is no variation between any of your hosts then there is no need for using variables/templates and using copy to install a static file is fine. Regarding the sourcing of the conf file, I would say it really depends on the context. It's normal for production hosts to contain files that have passwords inside them (e.g. config files for a web application to access a database using a password). What is this password for? Why are you sourcing it to a shell rather than storing it in a config file?
@JackReacher13 жыл бұрын
@@toptechskills I was thinking of doing this - 1. source db.cfg 2. mysql -u root -p $DBPASSWORD -h $DBHOST $DBNAME < dump.sql (sadly the second command gives me an error if I run it more than once) and obviously a warning. Is this a good idea? or Should I be importing the db.cfg file in the ansible playbook and use the mysql_db module to import the dump file?
@toptechskills3 жыл бұрын
Using the `mysql_db` module will allow you to set the variables from Ansible Vault from encrypted files on your control machine: docs.ansible.com/ansible/latest/user_guide/vault.html. If you want to use a file on the target machine, it's better to use an options file rather than sourcing shell variables: dev.mysql.com/doc/refman/8.0/en/option-files.html. You can template this file onto the target host with the `template` module and get variables from Ansible Vault, which I mentioned above. Hope that helps!
@cleitonsandestorres17102 жыл бұрын
great job ;-) congrats
@toptechskills2 жыл бұрын
Thank you!
@Triviaquizwitharya3 жыл бұрын
Good Explanation
@toptechskills3 жыл бұрын
Thank you! 🙏
@Triviaquizwitharya3 жыл бұрын
@@toptechskills can you please make an elaborate video on ansible roles
@avasivannarayana25835 жыл бұрын
in the .yml you just mentioned env: staging but in .j2 file there are three vars env, ansible_host and ansible_user where did you defined these all variables?
@toptechskills5 жыл бұрын
Hi Ava, thanks for your comment. `ansible_host` and `ansible_user` are "connection variables" that are available for connection types like SSH. If you're connecting to a host via SSH, these variables should be defined in all cases. Here's a link to the docs with more information about connection variables: docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#connection-variables
@umairksa20115 жыл бұрын
Which tool you are using to write code?
@toptechskills5 жыл бұрын
Hi Őɱɨ Ƥȅɳǵȗɩɳ, I'm using VS Code: code.visualstudio.com
@AmolGautam3 жыл бұрын
Thank you..
@toptechskills3 жыл бұрын
👍🙏
@ahsan-li7sh5 жыл бұрын
Great video
@toptechskills5 жыл бұрын
Thanks again for watching and commenting Ahsan! Glad you enjoyed it
@ahsan-li7sh5 жыл бұрын
@@toptechskills just few ideas l, it would be also nice if you have time to make videos about how to deploy website for example WordPress install, update and upgrade in docker container, deploying database using ansible, logging and monitor solutions with ansible videos. I know those are much work but I just wanted to share my idea
@ahsan-li7sh5 жыл бұрын
I mean some project based tutorial
@toptechskills5 жыл бұрын
@@ahsan-li7sh these are great ideas. I want to make some project based videos once I finish a few more module videos. My first idea was how to install Elasticsearch using Ansible, which is a pretty simple role. I really like the projects you suggested, I will try to make some of those ASAP. Thanks for the suggestions!
@ahsan-li7sh5 жыл бұрын
@@toptechskills looking forward to that
@RitamSur2 жыл бұрын
From where the value is coming for local_ip ?
@toptechskills2 жыл бұрын
The value comes from the "ansible_host", which is a "special connection variable" available for some connection plugins: docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#connection-variables. That page lists some other special variables. Host-specific variables might also come from "facts", which get set if "gather_facts" is true for a play: docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html Does that help?
@thamkinathkounain39014 жыл бұрын
Hi..Could you create one on how to sudo to root or some other user .. Im getting Sorry, user test is not allowed to execute '/bin/sh -c echo BECOME-SUCCESS-*** /usr/bin/python /home/test/.ansible/tmp/ansible-tmp-1597731916.1-91350856264363/command.py' as root on server.
@toptechskills4 жыл бұрын
Hi Thamkinath Kounain, there are some more details about this here: docs.ansible.com/ansible/latest/user_guide/become.html#id1 Hope this is helpful.
@KHUSHI59692 жыл бұрын
i tired to use in dest: {{ ssh_config_file }} , though no errors, it does not copy file defaults/main.yml as ssh_config_file: /etc/ssh/ssh_config templates/ssh_config.j2 file exists
@toptechskills2 жыл бұрын
Make sure to put quotes around template strings. Usually there would be an error message about that. If quotes around the var like "{{ ... }}" doesn't solve the problem, please post the full playbook and I'll help further.