Ansible Module - FileContent

codingdaddy·2022년 3월 19일
0

Ansible -Study

목록 보기
8/11
post-thumbnail

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
profile
Creative - DevOps in Korea

0개의 댓글