including variables in Ansible

[mohammedrafi@ansible1 ~]$ mkdir nginx
[mohammedrafi@ansible1 ~]$ cd nginx
[mohammedrafi@ansible1 nginx]$ mkdir tasks vars

[mohammedrafi@ansible1 nginx]$ touch tasks/environment.yml
[mohammedrafi@ansible1 nginx]$ touch vars/variables.yml
[mohammedrafi@ansible1 ~]$ tree nginx
|– nginx.yml
|– tasks
| `– environment.yml
`– vars
`– variables.yml
[mohammedrafi@ansible1 nginx]$ vim tasks/environment.yml

– name: install package
name: “{{ package }}”
state: latest
– name: start service
name: “{{ service }}”
state: “{{ svc_state }}”
[mohammedrafi@ansible1 nginx]$ vim vars/variables.yml

firewall_pkg: firewalld
[mohammedrafi@ansible1 nginx]$ vim nginx.yml

– name: anything
hosts: db
remote_user: mohammedrafi
become: true
become_method: sudo
become_user: root
rule: http
– name: Include the variables from yaml file
include_vars: vars/variables.yml

– name: include env variables and set the variables
include: tasks/environment.yml
package: nginx
service: nginx
svc_state: started

– name: install fiirewall pkg
name: “{{ firewall_pkg }}”
state: latest
– name: start firewalld
name: firewalld
state: started
enabled: true
[mohammedrafi@ansible1 nginx]$ ansible-playbook –syntax-check nginx.yml

playbook: nginx.yml
[mohammedrafi@ansible1 nginx]$ ansible-playbook nginx.yml

PLAY [anything] ****************************************************************

TASK [setup] *******************************************************************
ok: []

TASK [Include the variables from yaml file] ************************************
ok: []

TASK [install package] *********************************************************
ok: []

TASK [start service] ***********************************************************
ok: []

TASK [install fiirewall pkg] ***************************************************
ok: []

TASK [start firewalld] *********************************************************
ok: []

PLAY RECAP ********************************************************************* : ok=6 changed=0 unreachable=0 failed=0



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s