Ansible バックアップ作成と取得サンプル

環境
Ansible
RHEL8

操作方法
1.バックアップ先ディレクトリ作成

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
- name: create backup directory
file:
path=/config_backup/etc/ssh
state=directory
changed_when: false
- name: create backup directory file: path=/config_backup/etc/ssh state=directory changed_when: false
- name: create backup directory
  file:
    path=/config_backup/etc/ssh
    state=directory
  changed_when: false

2.バックアップ取得

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
- name: backup /etc/ssh/sshd_config
shell: cp -p /etc/ssh/sshd_config /config_backup/etc/ssh/sshd_config.`date +%Y%m%d%H%M%S`
- name: backup /etc/ssh/sshd_config shell: cp -p /etc/ssh/sshd_config /config_backup/etc/ssh/sshd_config.`date +%Y%m%d%H%M%S`
- name: backup /etc/ssh/sshd_config
  shell: cp -p /etc/ssh/sshd_config /config_backup/etc/ssh/sshd_config.`date +%Y%m%d%H%M%S`

3.設定内容の反映

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
- name: modify /etc/ssh/sshd_config
shell: cp {{ ansible_dir_ssh }}/etc/ssh/sshd_config /etc/ssh/
- name: modify /etc/ssh/sshd_config shell: cp {{ ansible_dir_ssh }}/etc/ssh/sshd_config /etc/ssh/
- name: modify /etc/ssh/sshd_config
  shell: cp {{ ansible_dir_ssh }}/etc/ssh/sshd_config /etc/ssh/

4.ファイル権限設定

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
- name: chown/chmod Setting ( sshd_config )
file:
path=/etc/ssh/sshd_config
owner=root
group=root
mode=0600
- name: chown/chmod Setting ( sshd_config ) file: path=/etc/ssh/sshd_config owner=root group=root mode=0600
- name: chown/chmod Setting ( sshd_config )
  file:
    path=/etc/ssh/sshd_config
    owner=root
    group=root
    mode=0600

 

Ansible

Posted by arkgame