Ansible Automation Choral
Ansible Automation Choral
Ansible Automation Choral
#Step 1
vim test.xml
#Insert the following code inside test.yml. Press "i" without quotes to insert
text.
---
- name: built-in variables
hosts: all
tasks:
- debug: var=hostvars[inventory_hostname]
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
#Step 2
touch afile.txt
vim test.yml
#Insert the following code inside test.yml. Press "i" without quotes to insert
text.
---
- hosts: all
become: yes
name: Copy file
tasks:
- debug:
- template: src=afile.txt dest=/home/ubuntu/afile_copy.txt
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
#Run the following command just to validate that the file was successfully
copied.
--------------------------------------------------------------------------------
-------------------------------
Which option will give you error while accessing your complex variable?
{{ ansible_eth0['ipv4']['address'] }}
This study source was downloaded by 100000839603243 from CourseHero.com on 01-17-2022 08:15:28 GMT -06:00
https://www.coursehero.com/file/66202666/Ansible-Automation-Choraltxt/
{{ ansible_eth0[ipv4][address] }} ~~~
{{ ansible_eth0.ipv4.address }}
{{ ansible_eth0["ipv4"]["address"] }}
You can skip the task of gathering facts through which of the following way?
gather_facts: no ~~~
gather_fact: no
--------------------------------------------------------------------------------
---------------------------------
#Step 1
vim tag.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- 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
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
#Step 2
This study source was downloaded by 100000839603243 from CourseHero.com on 01-17-2022 08:15:28 GMT -06:00
https://www.coursehero.com/file/66202666/Ansible-Automation-Choraltxt/
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"
--------------------------------------------------------------------------------
---------------------------------
# Workout - Include
#Step 1
touch apache.yml
touch playbook_include.yml
touch create_folder.yml
touch content.yml
touch nginx.yml
#Step 2
vim playbook_include.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- name: testing includes
hosts: all
sudo: yes
tasks:
- include: apache.yml
- include: content.yml
- include: create_folder.yml
- include: content.yml
- include: nginx.yml
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
#Step 3
vim apache.yml
---
- name: install apache2
apt: name=apache2 update_cache=yes state=latest
- name: displaying message
debug: msg="you are awesome!!"
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
#Step 4
vim create_folder.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
This study source was downloaded by 100000839603243 from CourseHero.com on 01-17-2022 08:15:28 GMT -06:00
https://www.coursehero.com/file/66202666/Ansible-Automation-Choraltxt/
to insert text.
---
- name: creating folder
file: path=/home/ubuntu/folder1 state=directory
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
#Step 5
vim content.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- name: list contents of directory in host
command: ls /home/ubuntu
register: contents
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
#Step 6
vim nginx.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- 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"
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
#Step 7
--------------------------------------------------------------------------------
--------------------------------
This keyword gives you flexibility to run specific part of your playbook.
This study source was downloaded by 100000839603243 from CourseHero.com on 01-17-2022 08:15:28 GMT -06:00
https://www.coursehero.com/file/66202666/Ansible-Automation-Choraltxt/
Tags ~~~
All the options
include
tag
You can run non tagged tasks using which magical word?
None of the options ~~~
nontag
untag
tagless
Tagging allows you to run or skip certain part of Playbook. Can you run tasks
that are not tagged?
Yes ~~~ No
--------------------------------------------------------------------------------
--------------------------------
#Step 2
mkdir roles
vim master_playbook.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- name: my first role in ansible
hosts: all
sudo: yes
roles:
- sample_role
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
#Step 4
This study source was downloaded by 100000839603243 from CourseHero.com on 01-17-2022 08:15:28 GMT -06:00
https://www.coursehero.com/file/66202666/Ansible-Automation-Choraltxt/
vim tasks/nginx.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- name: Installs nginx
apt: pkg=nginx state=installed update_cache=true
notify:
- start nginx
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
vim handlers/main.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- name: start nginx
service: name=nginx state=started
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
vim tasks/main.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- include: nginx.yml
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
cd ..
cd ..
pwd
ansible-playbook -i myhosts master_playbook.yml
#Step 5
cd roles/sample_role/
touch files/some-file.txt
vim tasks/copy-static.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- name: Copy a file
copy: src=some-file.txt dest=/home/ubuntu/file1.txt
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
vim tasks/main.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
This study source was downloaded by 100000839603243 from CourseHero.com on 01-17-2022 08:15:28 GMT -06:00
https://www.coursehero.com/file/66202666/Ansible-Automation-Choraltxt/
---
- include: nginx.yml
- include: copy-static.yml
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
cd ..
cd ..
pwd
ansible-playbook -i myhosts master_playbook.yml
#Step 6
cd roles/sample_role/
vim templates/template-file.j2
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
this is {{item}}
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
vim vars/main.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
var_x:
- 'variable x'
var_y:
- 'variable y'
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
vim tasks/copy-template.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- name: sample template - x
template:
src: template-file.j2
dest: /home/ubuntu/copy-template-file.j2
with_items: var_x
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
order to save changes.
vim tasks/main.yml
#Insert the following code inside plabook_include.yml. Press "i" without quotes
to insert text.
---
- include: nginx.yml
- include: copy-static.yml
- include: copy-template.yml
#Press "Esc" key and then write ":wq", without quotes, and then press "Enter" in
This study source was downloaded by 100000839603243 from CourseHero.com on 01-17-2022 08:15:28 GMT -06:00
https://www.coursehero.com/file/66202666/Ansible-Automation-Choraltxt/
order to save changes.
cd ..
cd ..
pwd
ansible-playbook -i myhosts master_playbook.yml
--------------------------------------------------------------------------------
---------------------------------
#Step 1
#Step 2
--------------------------------------------------------------------------------
---------------------------------
Which of the following can you use to delete your installed role?
remove ~~~
omit
delete
destroy
This study source was downloaded by 100000839603243 from CourseHero.com on 01-17-2022 08:15:28 GMT -06:00
https://www.coursehero.com/file/66202666/Ansible-Automation-Choraltxt/
--------------------------------------------------------------------------------
---------------------------------
You can view the details of a role using which of the following?
None Of The Options
ansible-galaxy info username.role ~~~
ansible-galaxy search username.role
ansible-galaxy init username.role
You can contribute your roles to Ansible community through GitHub Profile.
False True ~~~
How do you define Variables in Command Line Interface while executing playbook?
--variables-
--vars-extra
--extra-vars ~~~
None of the options
This study source was downloaded by 100000839603243 from CourseHero.com on 01-17-2022 08:15:28 GMT -06:00
https://www.coursehero.com/file/66202666/Ansible-Automation-Choraltxt/
Powered by TCPDF (www.tcpdf.org)