Ansible的设置

安装Ansible

使用yum进行安装

#RHEL7系の場合のURL
sudo yum localinstall https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
sudo yum install -y ansible
ansible --version

确认动作

尝试对本地主机进行ping。

[test_servers]
localhost
ansible -i inventory/test_inventory.ini test_servers -m ping --ask-pass

创建 Playbook 文件以进行连接。

---
- hosts: test_servers
  tasks:
  - name: create directory
    file:
      path: ~/tmp
      state: directory
      owner: kazunori
      mode: 0755
  - name: copy file
    copy:
      src: /etc/hosts
      dest: ~/tmp/hosts
      owner: kazunori
      mode: 0644
ansible-playbook -i ./inventory/test01_inventory.ini ./test_playbook.yml --ask-pass

其他

把配置文件放入主目录中。

cp /etc/ansible/ansible.cfg ~/.ansible.cfg

设置日志输出位置

...

log_path = ~/log/ansible.log

...
bannerAds