Ansible - Automation Choral Hands-on Solution | TCS Fresco Play | Fresco Play

0

Ansible - Automation Choral Hands-on Solution | TCS Fresco Play | Fresco Play

Disclaimer: The primary purpose of providing this solution is to assist and support anyone who are unable to complete these courses due to a technical issue or a lack of expertise. This website's information or data are solely for the purpose of knowledge and education.

Make an effort to understand these solutions and apply them to your Hands-On difficulties. (It is not advisable that copy and paste these solutions).

All Question of the MCQs Present Below for Ease Use Ctrl + F with the question name to find the Question. All the Best!

If you found answer for any of the questions is wrong. Please do mention in the comment section, could be useful for others. Thanks!

_______________________________________

Hands-on 1:

pwd: present working directory

ls: list contents in present directory

cd ..: move one folder up

mkdir: create directory

rm -rf dir_name: remove non-empty directory forcefully

rm file_name: remove file/directory

vi file_name: edit/create a file. Press i for insert mode, Esc to come out of insert mode, :wq to save the file and exit from vi editor, :q! to exit from vi editor without saving the file.

---

- hosts: all

  vars:

    var: 20

  tasks:    

    - debug: msg="Variable 'var' is set to {{ var }}"


****************************

Hands On2:

touch afile.txt.

ansible all -i myhosts -m copy -a "src=afile.txt dest=/home/ubuntu/"

vi test.yml

- name: copy files

  hosts: all

  tasks: 

    - name: copy file

      command: cp afile.txt /home/ubuntu/afile_copy.txt

      register: output

    - debug: var=output


***************************

Special Tags:

---

- name: Special Tags

  hosts: all

  sudo: yes

  tasks:

    - name: location 1

      debug: msg="california"      


    - name: location 2

      debug: msg="mumbai"

      tags:

        - tag1


    - name: location 3

      debug: msg="bangalore"

      tags:

        - tag2


    - name: location 4

      debug: msg="chennai"      

      tags:

        - always


ansible-playbook -i myhosts tag.yml --tags "tag1"

ansible-playbook -i myhosts tag.yml --tags "tagged"

ansible-playbook -i myhosts tag.yml --tags "untagged"

ansible-playbook -i myhosts tag.yml --tags "untagged" --skip-tags "always"


************************************

Create apache.yml file with the following content:


---

  - name: install apache2

    apt: name=apache2 update_cache=yes state=latest      

  - name: displaying message

    debug: msg="you are awesome!!"


Create create_folder.yml file with the following content:


---

- name: creating folder

  file: path=/home/ubuntu/folder1 state=directory


Create content.yml file with the following content:


---

  - name: list contents of directory in host

    command: ls /home/ubuntu

    register: contents


  - name: check dir is empty

    debug: msg="Directory is empty"

    when: contents.stdout == ""


  - name: check dir has contents

    debug: msg="Directory is not empty"

    when: contents.stdout != ""


Create nginx.yml file with the following content:


---

  - name: installing nginx

    hosts: all

    sudo: yes

    tasks:

      - name: install nginx

        apt: name=nginx update_cache=yes state=latest      


      - name: displaying message

        debug: msg="yayy!! nginx installed"


Execute the playbook: ansible-playbook -i myhosts playbook_include.yml


Ensure that all the files are included as tasks, except the last file (nginx.yml) which is included as play.

mkdir roles

sed -i '$ a roles_path = /home/scrapbook/tutorial/roles/' ansible.cfg



**************************************************

If you have any queries, please feel free to ask on the comment section.
If you want MCQs and Hands-On solutions for any courses, Please feel free to ask on the comment section too.

Please share and support our page!

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !

Join Telegram Channel

Join MNCAnswers To Get Instant Updates

Join Telegram Channel