My Ansible Setup for Tutorials

Поделиться
HTML-код
  • Опубликовано: 16 янв 2019
  • In this video I show you how I set up Ansible for my tutorial videos. I go through my ansible.cfg, inventory hosts file and my group variables for different hosts. In my tutorial videos I run Ansible playbooks against 2 hosts: one running CentOS 7 and another running Ubuntu Bionic 18.04. They are both just AWS EC2 instances running the base images for the OS.
    Thanks for watching and hope it's entertaining/useful for you! Hit me up in the comments if you have any questions or feedback 💪.
    Related & Channel
    ▶️ bit.ly/2VWid3D == Playlist of all Ansible videos
    ⭐️ bit.ly/2HavqCu == Subscribe to our RUclips Channel
    Our Site & Socials
    🌐 bit.ly/2shtKwZ == TopTechSkills.com
    🐦 bit.ly/2RkgZkk == @TopTechSkills on Twitter
    🐦 bit.ly/2AA19aN == @PercyGrunwald on Twitter
    😃 bit.ly/2ACQgEW == @TopTechSkills on Facebook
    🕹 bit.ly/2CWR3ST == @PercyGrunwald on Twitch
  • НаукаНаука

Комментарии • 36

  • @linuxdoesmatter5542
    @linuxdoesmatter5542 11 месяцев назад +1

    Thank you for sharing your knowledge. Your explanations are great.

  • @cooljassu
    @cooljassu 5 лет назад +1

    Hi percy... Thanks for this informative video on ansible modules. Can you please tell us about "cron" module too.

    • @toptechskills
      @toptechskills  5 лет назад +2

      Hi Jayshree, thanks for your comment, a few people have asked about the cron module, I will try to make a video for this useful module soon.

  • @eddie77084
    @eddie77084 4 года назад +1

    Hi Percy...Thanks for your great videos! How would your host file look if those were two CentOS machines instead of one being Ubuntu?

    • @toptechskills
      @toptechskills  4 года назад +2

      Hi Edward, thanks for your comment. Your file would look something like this:
      ```
      [centos]
      centos_host1 ansible_host=1.1.1.1
      centos_host2 ansible_host=1.1.1.2
      ```

  • @jiancarlotv
    @jiancarlotv 3 года назад +2

    Hi Percy.. I'm amaze with your videos. Can you show your configuration with your VSCode or make a tutorial how you do it? And how would you able to run the playbook from it. BTW Im using windows :) thanks

    • @toptechskills
      @toptechskills  3 года назад

      Hi Jian Carlo, thanks for your comment. My full VS Code configuration is available here: gist.github.com/percygrunwald/37e5b06dad39c47a42df3af93e4d11ab (you can use the marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync extension to load it). Unfortunately my configuration is for Mac, so the keybindings might not work. I will definitely try to make a video about IDE/editor configuration in future, it's really important to be able to use your editor effectively to make your programming experience enjoying and productive.
      The feature I'm using to run the playbook is the integrated terminal feature that is available by default in VS Code: code.visualstudio.com/docs/editor/integrated-terminal. I have it bound to Cmd + Shift + M, so I can bring it up quickly to run commands.
      Hope that helps!

  • @studio07photo
    @studio07photo Год назад +1

    Hello Percy, you have such amaizing content and I love your channel, I have a question, is it possible to setup code to run the ansible playbooks which are saved in my ansible server? or it has to be local as you have it here?
    Thank you!

    • @toptechskills
      @toptechskills  5 месяцев назад

      Thank you for your comment and sorry for my slow reply. You can definitely run ansible playbooks that are saved on a remote server. Simply install ansible on the remote server and run the playbook directly from your shell on the server, everything _should_ work pretty much identically to running it on your local machine.

  • @noblenetdk
    @noblenetdk 3 года назад +1

    Super

  • @jayakishoreudayagiri261
    @jayakishoreudayagiri261 4 года назад +1

    @Percy Grunwald from TopTechSkills,
    Could you please let me know how u setup ssh to those hosts without asking password, did you copy ssh key to those hosts?
    could you please do videos on Windows modules like mount NAS on windows server & execute commands on windows server

    • @toptechskills
      @toptechskills  4 года назад

      The hosts are in AWS EC2 and I've uploaded my personal SSH key as an EC2 keypair so that when the instances are launched the default user already has my personal SSH key in its authorized_keys. Check out this article for more info: docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#how-to-generate-your-own-key-and-import-it-to-aws.
      I'd definitely like to make videos on Windows in the future. Thanks for your comment, hope that was helpful.

  • @tamim2996
    @tamim2996 3 года назад +1

    Percy i must say your video is great....but for begginer it will be difficult to start...is it possible to add 1-2 introductory video to understand host, variavle, playbook etc. more specifically where to put what and how they connect each other...TIA

    • @toptechskills
      @toptechskills  3 года назад

      Hi Tamim, I hope to make some more introductory videos in future. In the meantime however, I can recommend Jeff Geerling's book "Ansible for DevOps" for a good introduction to these concepts. Sorry I can't help more, good luck.

  • @rickhighness5539
    @rickhighness5539 5 лет назад +1

    What editor are you using for your demos?

    • @toptechskills
      @toptechskills  5 лет назад +2

      Hi Rick, I'm using Visual Studio Code with the Ansible extension by Microsoft.
      code.visualstudio.com
      marketplace.visualstudio.com/items?itemName=vscoss.vscode-ansible
      Thanks for watching, hope you enjoyed the video.

  • @dh00mketu
    @dh00mketu 9 месяцев назад +1

    Why do you use inventory directory instead of just a file? Also, great tutorial ✌

    • @toptechskills
      @toptechskills  5 месяцев назад +2

      That's a good question, I guess for me it's a matter of habit because of my work over the years. We've often ended up with multiple different inventories for different environments or providers. With a directory, you can keep all those different inventories in one place.

  • @kajalrai6681
    @kajalrai6681 5 лет назад +1

    Which editor are you using to write a script?

    • @toptechskills
      @toptechskills  5 лет назад +1

      I'm using Visual Studio Code with the Ansible plugin by Microsoft. Highly recommend it.

  • @kajalrai6681
    @kajalrai6681 5 лет назад +1

    How to run .yml file and can I create a file using vim editor.

    • @toptechskills
      @toptechskills  5 лет назад

      You run Ansible playbooks with the "ansible-playbook" command.
      You can definitely use vim for writing Ansible roles and playbooks.

  • @melontrophy7483
    @melontrophy7483 3 года назад +1

    I can't seem to access my ubuntu server from alpine linux using ssh. I keep getting the permission denied error (publickey, keyboard-interactive). I tried everything I saw on Google but nothing worked. How do i set up my SSH keys? or maybe my ip address is wrong, how do i know the ip address in my remote host?

    • @toptechskills
      @toptechskills  3 года назад

      Hi, how did you get your Ubuntu server? If it's through some service like AWS, the service itself will give you the IP of your host in the console. The fact that you're getting a permission denied error implies to me that the server you're trying to connect to is up and responding to SSH (which is a good sign). If the instance was created in AWS EC2, you would have selected a keypair to launch the instance with, this keypair would need to be loaded into your SSH agent with `ssh-add` or by using the `-i` argument to the `ssh` command to specify the identity/key to try to connect with.

  • @johnfinny100
    @johnfinny100 4 года назад +1

    Could you please share me distribute ssh key to multiple servers video, so i can ssh to all servers.

    • @toptechskills
      @toptechskills  4 года назад

      Hi John, I imported my SSH key as an AWS EC2 keypair and use that to start the instances, so my personal SSH key allows me to log in by default when launching an instance. Check this out for more info: docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#how-to-generate-your-own-key-and-import-it-to-aws

  • @JackReacher1
    @JackReacher1 3 года назад +1

    I am able to connect using my private key to both the instances but I get this error with the same setup which 2 ubuntu instances on aws
    $ ansible-playbook file.yml
    PLAY [run task on all hosts] ***************************************************
    TASK [Gathering Facts] *********************************************************
    fatal: [ubuntu_1]: UNREACHABLE! => {"changed": false, "msg": "Data could not be sent to remote host \"\". Make sure this host can be reached over ssh: ubuntu@: Permission denied (publickey).
    ", "unreachable": true}
    fatal: [ubuntu_2]: UNREACHABLE! => {"changed": false, "msg": "Data could not be sent to remote host \"\". Make sure this host can be reached over ssh: ubuntu@: Permission denied (publickey).
    ", "unreachable": true}
    PLAY RECAP *********************************************************************
    ubuntu_1 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
    ubuntu_2 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
    I was able to use ssh with my pem key but running file.yml provides me with this error, please help.

    • @toptechskills
      @toptechskills  3 года назад +1

      Looks like the issue is that it's trying to connect to a hosts "public_ip" and "public_ip_2". These would either need to be set up as aliases for hosts in your ~/.ssh/config file or as aliases for IPs in your /etc/hosts file.
      Most likely what's going on here is that your Ansible inventory is not configured correctly and you may be trying to use a variable for the value of `ansible_host`, which is not possible (docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#inventory-aliases).
      If you share your inventory entries for these 2 hosts, I can provide more specific advice.
      Hope that helps, thanks.

    • @JackReacher1
      @JackReacher1 3 года назад

      @@toptechskills My Host file is:
      [ubuntu]
      ansible_user=ubuntu
      ansible_user=ubuntu
      I was able to connect to the instances and run the plays but I have to use this command to run the playbook:
      ansible-playbook --private-key ansible.pem file.yml
      I have to mention the private key in the command, how are you able to run the playbook without this?

    • @toptechskills
      @toptechskills  3 года назад +1

      Ah I see, in that case I'd suggest doing the setup in your ~/.ssh/config to specify the identity file for the hosts there so you don't need to specify it for Ansible directly. Ansible uses SSH to connect to the instances and will apply your SSH config when doing so, so any settings you apply there will also be applied. For example
      # ~/.ssh/config
      Host ,
      IdentityFile /path/to/ansible.pem
      User ubuntu
      # ./inventory/hosts.ini
      [ubuntu]
      The SSH config will apply your private key and also set the user for you, so this doesn't need to be set in Ansible.
      Hope that helps.

  • @vishnubysani1
    @vishnubysani1 3 года назад +1

    Hello Percy,
    Your tutorials are amazing. Thanks.
    Today, I see that Ansible plugin is now RETIRED.
    Any other GUI options ?
    marketplace.visualstudio.com/items?itemName=vscoss.vscode-ansible&ssr=false#overview

    • @toptechskills
      @toptechskills  3 года назад

      Thank you for your comment, I saw this as well. I have switched to using github.com/haad/vs-language-ansible as it's the next most popular extension for Ansible. It seems fine so far, maybe you could give it a go and let me know how your experience is.
      Thanks!

    • @vishnubysani1
      @vishnubysani1 3 года назад +1

      @@toptechskills Thanks for the reply Percy. Will try it and update

    • @vishnubysani1
      @vishnubysani1 3 года назад +1

      Hi Percy,
      I am working on mac where VS is installed. My Ansible controller is AWS VM and I have two control nodes on AWS.
      Is it possible to run a playbook from my mac on AWS controller VM ?
      Thanks,
      Vishnu

    • @toptechskills
      @toptechskills  3 года назад

      In that case, your Mac becomes the control machine and the AWS host is the target. This is perfectly normal and there should be no issues with that. That said, you'll just need to make sure that you can access your AWS host from your Mac via SSH. In AWS, that will require you to configure the security groups to allow inbound connections from your Mac and ensure that you have your SSH authentication set up properly.
      Is there something you've tried that didn't work?