Ansible Module - FileContent
Create a playbook ~/playbooks/file.yml to create a blank file /opt/data/perm.txt with 0640 permissions on web1 node.
- hosts: web1
tasks:
- name: create file
file:
path: /opt/data/perm.txt
state: touch
mode: '0640'
Using a playbook ~/playbooks/writefile.yml create /var/index.html file on web1 node with content “This line was added by Ansible lineinfile module!”
- name: Create index.html on web1
hosts: web1
tasks:
- lineinfile:
path: /var/index.html
line: 'This line was added by Ansible lineinfile module!'
create: yes
/opt/data 디렉토리에서 2분보다 오래되고 크기가 1MB 이상인 파일을 재귀적으로 찾는 플레이북 ~/playbooks/find.yml이 있습니다. 또한 /opt 디렉토리 아래에 해당 파일을 복사합니다. 그러나 누락된 매개변수가 있으므로 예상대로 작동하지 않으므로 살펴보고 적절하게 변경하십시오.
- hosts: web1
tasks:
- name: Find files
find:
paths: /opt/data
age: 2m
size: 1m
recurse: yes
register: file
- name: Copy files
command: "cp {{ item.path }} /opt"
with_items: "{{ file.files }}"
On web1 node we want to run our httpd server on port 8080.
Create a playbook ~/playbooks/httpd.yml to change port 80 to 8080 in /etc/httpd/conf/httpd.conf file using replace module.
make sure Ansible restarts httpd service after making the change.
Listen 80 is the parameter that need to be changed in /etc/httpd/conf/httpd.conf
- name: replace port 80 to 8080
hosts: web1
tasks:
- replace:
path: /etc/httpd/conf/httpd.conf
regexp: 'Listen 80'
replace: 'Listen 8080'
- service:
name: httpd
state: restarted
Author And Source
이 문제에 관하여(Ansible Module - FileContent), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@codingdaddy/Ansible-Module-FileContent저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)