通过ansible 配置F5
2019-05-07 本文已影响0人
bjmingyang
ansible 内置F5 模块,以为直接使用就好,结果发现还是要修改一些
TASK [Add pool member] *******************************************************************************************************************************************************************************************************************
task path: /Users/wangmingyang/Documents/code/ansible/roles/f5/add_member_to_pool.yaml:6
[DEPRECATION WARNING]: Param 'server' is deprecated. See the module docs for more information. This feature will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
[DEPRECATION WARNING]: Param 'user' is deprecated. See the module docs for more information. This feature will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
[DEPRECATION WARNING]: Param 'password' is deprecated. See the module docs for more information. This feature will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
fatal: [172.16.8.20 -> localhost]: FAILED! => {"changed": false, "msg": "The python f5-sdk module is required"}
to retry, use: --limit
首先是 The python f5-sdk module is required 这个报错
简单pip install f5-sdk 发现没解决问题,翻了翻官方社区,需要
ansible-galaxy install -f f5devcentral.f5ansible,master
然后在playbook 里面引用这个role
然后是会出
build_ssl_validation_error\nansible.module_utils.urls.SSLValidationError: Failed to validate the SSL certificate for 172.16.8.20:443. Make sure your managed systems have a valid CA certificate installed. You can use validate_certs=False if you do not need to confirm the servers identity but this is unsafe and not recommended. Paths checked for this platform: /etc/ssl/certs, /etc/ansible, /usr/local/etc/openssl. The exception msg was: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1056).\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
简化一下就是说证书没有可信签名,这个需要在playbook里面关闭证书验证
最后是ansible 2.7 对循环的语句做了更改,从with_* 更改成直接loop ,从代码上看,更简洁一点,不过我们这些从2.2 开始玩的人就又要更新一遍知识了
最后还是贴一个我简单的例子,添加host 到 pool
---
- hosts: f5
#become: yes
gather_facts: False
roles:
- role: f5devcentral.f5ansible
tasks:
- name: Add pool member
bigip_pool_member:
server: 172.16.1.1
user: admin
validate_certs: False
password: xyz123
state: present
pool: test_new_fe
partition: Common
host: "{{ item }}"
port: 80
loop:
- 172.16.1.2
- 192.168.100.10
delegate_to: localhost
如果想同时添加server 和 ip 和 pool ,用ansible的循环就好,要求ansible 版本在2.7 以上
---
- hosts: f5
#become: yes
gather_facts: False
roles:
- role: f5devcentral.f5ansible
tasks:
- name: Add pool member
bigip_pool_member:
server: 172.16.1.1
user: admin
validate_certs: False
password: xyz123
state: present
pool: "{{ item.pools }}"
partition: Common
host: "{{ item.name }}"
port: 80
loop:
- { name: 'testserver01', groups: 'wheel' , pools: 'xyz01 ' }
- { name: 'testserver01', groups: 'wheel' , pools: 'xyz02 ' }
delegate_to: localhost