---
- name: variable test
hosts: managed
gather_facts: false
vars:
message: Ansible variable test
tasks:
- name: print variable
debug:
msg="{{ message }}"
---
- name: variable test
hosts: managed
gather_facts: false
vars:
message: Ansible variable test
tasks:
- name: debug module test
debug:
msg:
- name: print variable
debug:
msg="message variable -> {{ message }}"
- name: task variable test
hosts: private
gather_facts: false
vars:
file_path: /home/ec2-user/work
tasks:
- name: current directory
file:
path: "{{ file_path }}"
state: touch
register: result
ignore_errors: true
- name: print result
debug:
msg: "{{ result }}"
---
- name: create directory & change directory
hosts: private
gather_facts: False
tasks:
- name: create directory
file:
path: "/home/ec2-user/{{file_name}}"
state: directory
register: result_create
- name: change directory
shell: cd "/home/ec2-user/{{file_name}}"
- name: debug
debug:
var: result_create
확인
---
- name: copy file
hosts: "{{ host_names }}"
gather_facts: False
tasks:
- name: copy file
copy:
src: "{{ src_file }}"
dest: "{{ dest_file }}"
register: result
- name: confirm copy
shell: ls -lF "{{ dest_file }}"
register: result_confirm
- name: debug
debug:
var: result
---
- name: confirm facts
hosts: private
gather_facts: True
tasks:
- name: ansible facts
debug:
msg: "{{ansible_facts['user_id']}}"