Skip to content

Configure Target Node by using the variable file of the same name as that of the Target Node’s OS name

Notifications You must be signed in to change notification settings

thespecguy/variable_files_target_node_config_ansible

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Configuration of Target Node by using Variable file having same name as the OS in Ansible

ansible_redhat_ubuntu

Objective

Configure Target Node by using the variable file of the same name as that of the Target Node’s OS name.

Content

  • Project Understanding
  • Output

Project Understanding

Let’s understand the implementation part by part

Part 1 : Ansible Playbook (main.yml)

- hosts: target_os
  vars_files:
    - "{{ ansible_facts['distribution'] }}.yml"
    
  tasks:
    - name: Webserver Installation
      package:
        name: "{{ webserver_package_name }}"
        state: present
        
    - name: Placing Web Page in Document Root
      template:
        dest: "/var/www/html/index.html"
        src: "/t14_3/web_page/index.html"
        
    - name: Enabling Webserver service
      service:
        name: "{{ service }}"
        state: started
        enabled: yes

Important Points

  • The name of variable file is updated dynamically as per the target node’s OS and which makes it easier to configure webserver as per OS. It internally uses the facts associated with a particular target node.
  • Two OS are considered over here, one is RedHat 8 and the other one is Ubuntu 20.04. The software for setting up webserver has different name in both OS i.e., httpd in RedHat 8 and apache2 in Ubuntu.

Part 2 : Variable Files

RedHat.yml

webserver_package_name: httpd
service: httpd

Ubuntu.yml

webserver_package_name: apache2
service: apache2

Part 3 : Web Page

index.html

Hello, this is {{ ansible_facts['distribution'] }}

Note:

  • Unlike RedHat 8, root account can’t be logged into separately in case of Ubuntu OS. In order to use root power in Ubuntu OS, sudo password needs to be provided.
  • Also, in the inventory file, general user’s credential needs to be specified for Ansible to access the OS via SSH in case of Ubuntu.
  • Software can’t be installed in Ubuntu OS without root power. In order to solve this issue an option could be provided with the ansible-playbook command as mentioned below:
ansible-playbook main.yml --ask-become-pass
  • The above command works if the sudo password for both the OS is same.

. . .


Output

redhat_output

Web Page Output in RedHat 8



ubuntu_output

Web Page Output in Ubuntu 20.04




. . .


Thank You 😃

About

Configure Target Node by using the variable file of the same name as that of the Target Node’s OS name

Topics

Resources

Stars

Watchers

Forks

Languages