ansible-playbook 安装配置zabbix iptables selinux ntp alipay源,zabbixiptables


执行方法:
[root@centos ansible]# pwd
/etc/ansible
[root@centos ansible]# ansible-playbook ansible-common.yml


任务目录结构:
[root@centos ansible]# tree roles/ansible-common/
roles/ansible-common/
├── files
│   ├── zabbix-2.4.6.tar.gz
│   └── zabbix_agentd_install.sh.tar.gz
├── handlers
│   └── main.yml
├── tasks
│   └── main.yml
├── templates
│   ├── iptables.j2
│   └── ntp.conf.j2
└── vars

5 directories, 6 files



文件内容:
/etc/ansible/
[root@centos ansible]#ll

total 28

-rw-r--r--.    1 root root 8625 Oct 11 02:41     ansible.cfg

-rw-r--r--.    1 root root 68 Feb 15 16:41         ansible-common.yml

-rw-r--r--.    1 root root 60 Feb 14 09:36         findfile.yml

-rw-r--r--.    1 root root 1071 Feb 15 16:42    hosts

drwxr-xr-x. 6 root root 4096 Feb 15 16:38    roles


[root@centos ansible]#cat host
[testhost]
192.168.1.241
[zabbixhost]
192.168.1.241

[root@centos ansible]# cat ansible-common.yml 
- hosts: zabbixhost
  remote_user: root
  roles:
  - ansible-common

[root@centos ansible]# cat roles/ansible-common/tasks/main.yml 
---
#环境是centos6


- name: alipay source configuration
  #shell: wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo && yum makecache
  get_url: url=http://mirrors.aliyun.com/repo/Centos-6.repo dest=/etc/yum.repos.d/CentOS-Base.repo mode=0644 force=yes 
  notify:
   - yum makecache


- name: Install python bindings for SE Linux and NTP
  yum: name={{ item }} state=present
  with_items:
   - libselinux-python
   - libsemanage-python
   - ntp 


#- name: change hostname
#  shell: sed -i 's/HOSTNAME=.*/HOSTNAME={{ ansible_all_ipv4_addresses[0] }}/g'  /etc/sysconfig/network
#  when: ansible_all_ipv4_addresses[0] == "192.168.1.241"


- name: test to see if selinux is running
  command: getenforce
  register: sestatus
  changed_when: false


- name: Configure ntp file
  template: src=ntp.conf.j2 dest=/etc/ntp.conf
  tags: ntp
  notify: restart ntp


- name: Start the ntp service
  service: name=ntpd state=started enabled=yes
  tags: ntp


- name: Copy zabbix client files  to zabbixhost
  copy: src=zabbix-2.4.6.tar.gz dest=/root/zabbix-2.4.6.tar.gz mode=0644


- name: Copy Zabbix install Script tar.gz to zabbixhost
  copy: src=zabbix_agentd_install.sh.tar.gz dest=/root/zabbix_agentd_install.sh.tar.gz mode=644
  #notify:
   # Extract zabbix install script 
   #- zabbix install-script


- name: extract zabbix install script
  unarchive: src=/root/zabbix_agentd_install.sh.tar.gz dest=/root copy=no mode=755  
  tags: zabbix install
  notify: zabbix install script
  
- name: zabbixhost client iptables configuration
  template: src=iptables.j2 dest=/etc/sysconfig/iptables
  notify: restart iptables
  tags: iptables configurate       

项目文件:http://pan.baidu.com/s/1sjWfIRN



相关内容

    暂无相关文章