How to create a variable in Ansible Playbook

0 votes

Hi Guys,

I am new in Ansible. I want to create a variable so that I can use that in my ansible-playbook several times. How can I do that?

Aug 2, 2020 in Ansible by akhtar
• 38,180 points
311 views

1 answer to this question.

0 votes

Hi@akhtar,

Variable in playbooks are very similar to using variables in any programming language. It helps you to use and assign a value to a variable and use that anywhere in the playbook.

- hosts: all
  vars:
    - pname: "httpd"
  tasks:
  - package:
      name: "{{ pname }}"
      state: present
answered Aug 2, 2020 by MD
• 95,220 points

Related Questions In Ansible

0 votes
1 answer

How to create a group of Managed Nodes in Ansible?

Hi@akhtar, You can use tags in your inventory ...READ MORE

answered Aug 1, 2020 in Ansible by MD
• 95,220 points
157 views
0 votes
1 answer

How to overwrite the content of a file in remote systems using Ansible playbook?

Hi@akhtar, You can find one argument in the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,220 points
3,616 views
0 votes
1 answer

How to capture the output of a task in Ansible Playbook?

Hi@akhtar, Ansible registers module used to capture/store the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,220 points
5,376 views
0 votes
1 answer

How to create a docker container using Ansible playbook?

Hi@akhtar, You can use the docker_container module in ...READ MORE

answered Aug 7, 2020 in Ansible by MD
• 95,220 points
2,227 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,138 views
+2 votes
1 answer
0 votes
1 answer

How to create a security group in AWS using Ansible-Playbook?

Hi@akhtar, You can use the ec2_group module in ...READ MORE

answered Aug 13, 2020 in Ansible by MD
• 95,220 points
976 views
0 votes
2 answers

How to create a directory in remote nodes using Ansible-Playbook?

You can read install and setup apache ...READ MORE

answered Aug 23, 2020 in Ansible by anonymous
• 160 points
554 views