Difference between revisions of "Ansible Variables"
Jump to navigation
Jump to search
(Created page with "=Ansible Variables= --- - name: setup apache ser er hosts: localhost vars: variablename: apache2 tasks: apt: name: "{{ variablename }}" state: present tags: i-apache -name: start apache service: name: "{{ variablename }}" state: started tags: start_apache2") |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Ansible Variables= | =Ansible Variables= | ||
<pre> | |||
--- | --- | ||
- name: setup apache ser er | - name: setup apache ser er | ||
Line 16: | Line 16: | ||
state: started | state: started | ||
tags: start_apache2 | tags: start_apache2 | ||
</pre> | |||
'''Copy A File''' | |||
<pre> | |||
--- | |||
- name: copy file | |||
hosts: all | |||
vars: | |||
srcfile: /home/somefile.txt | |||
tasks: | |||
-name: copy file | |||
copy: | |||
src: ""{{ srcfile }}"" | |||
dest: /tmp | |||
owner: wheel | |||
group: www | |||
mode: 0644 | |||
</pre> | |||
'''Create a file''' | |||
<pre> | |||
--- | |||
- name: create a file | |||
hosts: all | |||
vars: | |||
filename: myfile | |||
tasks: | |||
-name: create file | |||
file: | |||
state: touch | |||
path: /tmp"{{ filename }}".txt | |||
</pre> | |||
==Get input from user== | |||
<pre> | |||
--- | |||
- hosts: localhost | |||
vars_prompt: | |||
- name: fname | |||
prompt: "what is the filename" | |||
private: no | |||
tasks: | |||
- name: copy file | |||
copy: | |||
src: ~/{{ fname }} | |||
dest: /etc/ansible/playbook | |||
</pre> | |||
=[[Ansible| Ansible Menu]]= | |||
[[Category:Ansible]] |
Latest revision as of 17:49, 14 July 2022
Ansible Variables
--- - name: setup apache ser er hosts: localhost vars: variablename: apache2 tasks: apt: name: "{{ variablename }}" state: present tags: i-apache -name: start apache service: name: "{{ variablename }}" state: started tags: start_apache2
Copy A File
--- - name: copy file hosts: all vars: srcfile: /home/somefile.txt tasks: -name: copy file copy: src: ""{{ srcfile }}"" dest: /tmp owner: wheel group: www mode: 0644
Create a file
--- - name: create a file hosts: all vars: filename: myfile tasks: -name: create file file: state: touch path: /tmp"{{ filename }}".txt
Get input from user
--- - hosts: localhost vars_prompt: - name: fname prompt: "what is the filename" private: no tasks: - name: copy file copy: src: ~/{{ fname }} dest: /etc/ansible/playbook