Ansible for beginners -- Complete end-to-end tutorial video with practical solution

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 28

  • @DevOpsMela
    @DevOpsMela  ปีที่แล้ว +6

    ## Ansible Installation on Ubuntu:20.04 ##
    sudo apt update
    sudo apt install software-properties-common
    sudo add-apt-repository --yes --update ppa:ansible/ansible
    sudo apt install ansible
    ## Ansible Version ##
    - ansible --version
    ## Setting Ansible Inventory ##
    vi /etc/ansible/hosts
    ## Test Inventory file ##
    ansible all -m ping
    ansible -i hosts all -m ping -u devopsmela -k {-u = become sudo, -k = prompt for pass}
    ** Escalate permission with -b flag **
    ## Running through custom inventory file ##
    ansible -i hosts all -m ping
    ## Run without ansible_ssh_pass option in inventory file
    ansible -i hosts all -m ping -k
    ## Setup Ansible Variables ##
    ansible_connection=(ssh/local)
    ansible_user=
    ansible_ssh_pass=
    ansible_port=
    ansible_host=
    ## Ansible AD-HOC ##
    ## Modules:
    ** shell
    - ansible localhost -m shell -a 'ls' {-m = module, -a = module args}
    ** copy
    - ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts"
    ** file
    - ansible webservers -m file -a "dest=/srv/foo/a.txt mode=600"
    - ansible webservers -m file -a "dest=/srv/foo/b.txt mode=600 owner=mdehaan group=mdehaan"
    ## Create directory:
    - ansible webservers -m file -a "dest=/path/to/c mode=755 owner=mdehaan group=mdehaan state=directory"
    ## Delete directory:
    - ansible webservers -m file -a "dest=/path/to/c state=absent"
    ** apt
    - ansible webservers -b -m apt -a "name=apache2 state=present"
    - ansible webservers -m copy -a "src=index.html dest=/var/www/html"
    ** setup {Gathering facts}
    - ansible all -m setup
    ** Disable Host_key_check **
    ansible-config init --disabled > ansible.cfg
    vi /etc/ansible/ansible.cfg
    host_key_check=False
    ## Ansible Playbooks ##
    ** Install Apache and Start services
    ---
    - name: Apache Install
    hosts: all
    become: true
    tasks:
    - name: Update OS
    command: apt update
    - name: Apache Latest Version
    apt:
    name: apache2
    state: present
    - name: Apache Service Start
    service:
    name: apache2
    state: started
    - name: Copy config file
    copy:
    src: index.html
    dest: /var/www/html/index.html
    ** Adding VARIABLES to the playbook
    ---
    - name: Apache Install
    hosts: all
    become: true
    vars:
    app: apache2
    tasks:
    - name: Update OS
    command: apt update
    - name: Apache Latest Version
    apt:
    name: "{{ app }}"
    state: present
    - name: Apache Service Start
    service:
    name: "{{ app }}"
    state: started
    - name: Copy config file
    copy:
    src: index.html
    dest: /var/www/html/index.html
    ## Ansible Roles ##
    - ansible-galaxy init apache_role
    ** Add below code in tasks/main.yml
    - name: Update OS
    command: apt update
    - name: Apache Latest Version
    apt:
    name: "{{ app }}"
    state: present
    - name: Apache Service Start
    service:
    name: "{{ app }}"
    state: started
    - name: Copy config file
    copy:
    src: index.html
    dest: /var/www/html/index.html
    ** Add below code in vars/main.yml
    app: apache2
    ** Create playbook to use ansible roles
    - hosts: all
    become: true
    roles:
    - apache_role
    ## Ansible Integration with Azure DevOps ##
    - Launch Ubuntu VM on Azure Cloud
    - Setup Azure CLI
    {curl -sL aka.ms/InstallAzureCLIDeb | sudo bash}
    - Run az login command
    - Run az account show (copy subscription Id)
    ** Create service principal **
    az ad sp create-for-rbac --name ansible-sp-dev --role Contributor --scopes /subscriptions/
    - Create mkdir ~/.azure
    - Edit file ~/.azure/credentials and add below blocks
    [default]
    subscription_id=?
    client_id=?
    secret=?
    tenant=?
    ** Generate private and public keys **
    - ssh-keygen -m PEM -t rsa -b 2048
    - chmod 755 ~/.ssh
    - touch ~/.ssh/authorized_keys
    - chmod 644 ~/.ssh/authorized_keys
    - ssh-copy-id devopsmela@127.0.0.1
    - ssh devopsmela@127.0.0.1 {Verify key login}
    - cat ~/.ssh/id_rsa {Copy the private key}
    ** Create SSH Service Connection in Azure DevOps
    - paste the private key copied
    ** Create release pipeline
    - Ansible location --> Remote Machine
    - Playbook --> Source --> Agent Machine {If playbook and others are part of repositories}
    - Inventory Location --> Use default inventory file

  • @shakthidharga9967
    @shakthidharga9967 ปีที่แล้ว +3

    You're doing a quality video's. It's really helping me in my interview preparation and learning tools

    • @DevOpsMela
      @DevOpsMela  ปีที่แล้ว

      Thanks! For the valuable feedback…

  • @venkatavamsi6930
    @venkatavamsi6930 ปีที่แล้ว +2

    You desever a million views bro.. Thank you so much

  • @amadoudiop6634
    @amadoudiop6634 9 หลายเดือนก่อน +1

    Thank you very for this awesome tutorial

    • @DevOpsMela
      @DevOpsMela  9 หลายเดือนก่อน

      Welcome 🙌

  • @WorldofGowtham
    @WorldofGowtham ปีที่แล้ว +1

    Great work. it is really helpful...The way you teach is very clear and understandable...Now, i got some knowledge on Ansible. Thank you very much for the video.
    one question:
    using Ansible, can we configure windows also or it is useful to configure Linux only?

    • @DevOpsMela
      @DevOpsMela  ปีที่แล้ว

      Thanks! for the valuable feedback
      Yes! You can configure windows too

  • @danielventurini7273
    @danielventurini7273 ปีที่แล้ว +1

    I ran over two other videos on TH-cam, but your one is the best I found today.
    Keep going, bro
    +1 sub

    • @DevOpsMela
      @DevOpsMela  ปีที่แล้ว +1

      Thanks! for the valuable feedback

  • @Arun_7793
    @Arun_7793 7 หลายเดือนก่อน +1

    how kubernetes and secrets manager or vaults are integrated?

    • @DevOpsMela
      @DevOpsMela  7 หลายเดือนก่อน

      Will get the topic covered in the next upcoming video’s

  • @Kelly-wy2uf
    @Kelly-wy2uf 3 หลายเดือนก่อน +1

    Thanks good video, but if you want to be great video , 😊you would show how to use in production, ie dont disable host key check. Setup vault all from beginning, just some advice. So many videos show the "lazy" way. Standout by going extra mile

    • @DevOpsMela
      @DevOpsMela  3 หลายเดือนก่อน

      Thanks! Kelly for the suggestion
      Definitely will covers those in my advance topics

  • @Raviteja6031
    @Raviteja6031 ปีที่แล้ว +2

    Nice video...
    please make a video on Ansible-vault

    • @DevOpsMela
      @DevOpsMela  ปีที่แล้ว

      Sure! Thanks for suggestion

  • @Letmework247
    @Letmework247 10 หลายเดือนก่อน +1

    Nice job

    • @DevOpsMela
      @DevOpsMela  10 หลายเดือนก่อน

      Thanks!

  • @seemasingh4619
    @seemasingh4619 ปีที่แล้ว +1

    Perfect... Thanks!!

  • @nagulmeerashaik5336
    @nagulmeerashaik5336 ปีที่แล้ว +1

    Thanks bro😊🎉

  • @Arun_7793
    @Arun_7793 7 หลายเดือนก่อน

    please explain
    how the vault is integrated

    • @DevOpsMela
      @DevOpsMela  7 หลายเดือนก่อน

      👍🏻 will get it covered

    • @Arun_7793
      @Arun_7793 7 หลายเดือนก่อน

      @@DevOpsMela thank you for responding

  • @harishchary3404
    @harishchary3404 ปีที่แล้ว +2

    Bro I want follow your LinkedIn

    • @DevOpsMela
      @DevOpsMela  ปีที่แล้ว

      Check my website devopsmela.in I got my Linkedln link mentioned…