ansible-runner自动创建ceph集群

24 篇文章 1 订阅

Ansible-runner

安装ansible-runner

pip3 install ansible-runner

遇到问题:

  • 缺少psutil/_psutil_common.c:9:20: 致命错误:Python.h:没有那个文件或目录

    如果是python2环境则需要安装python3-dev,注意一定是安装python3-dev,安装python-dev没有用!!

安装ansible

pip3 install ansible==2.9.17

注意:

  • 如果之前使用yum安装了ansible还需要用pip3进行安装,否则找不到依赖

    并且一定要是2.9.17版本,因为ceph-ansible暂时不支持ansible2.10以及以上版本

编写代码

  • 代码结构如下

    image-20210217154229659

    main.py为执行代码

    代码如下:

    import ansible_runner
    import sys
    sys.path.append("/usr/local/lib/python3.6/site-packages") #找到ansible-runner依赖
    # become_password = getpass.getpass("Please type in the become password: ")
    # password_dict={"^SSH [pP]assword:$": become_password}
    extra_dict={"ansible_sudo_pass": "123"} #ceph集群主机密码
    
    #设置运行配置信息
    rc = ansible_runner.RunnerConfig(private_data_dir="./private_data_dir/",
                           playbook="/root/project/private_data_dir/project/ceph-ansible-stable-4.0/site.yaml",
                           extravars=extra_dict)
    rc.prepare()
    ansible_command = rc.generate_ansible_command()
    print(ansible_command)
    print(rc.roles_path)
    
    #运行
    r = ansible_runner.Runner(config=rc)
    r.run()
    
    # r = ansible_runner.run(private_data_dir="./private_data_dir/", host_pattern='ceph', module='shell', module_args='whoami')
    
    #输出结果
    print("--------\n")
    print("{}: {}".format(r.status, r.rc))
    
    

    private_data_dir存放如下东西:

    image-20210217154418334

执行main.py

python3 main.py

遇到问题:

  • TASK [ceph-common : generate ceph configuration file] **************************
    fatal: [mon1.ceph.pp.sd.lbn.fr]: FAILED! => {"failed": true, "msg": "module (config_template) is missing interpreter line"}
    fatal: [mon2.ceph.pp.sd.lbn.fr]: FAILED! => {"failed": true, "msg": "module (config_template) is missing interpreter line"}
    fatal: [mon3.ceph.pp.sd.lbn.fr]: FAILED! => {"failed": true, "msg": "module (config_template) is missing interpreter line"}
    

    解决办法:

    原因是没有修改ansible.cfg中的action_plugin默认路径,需要将默认路径修改为ansible当前工作路径:

    此处我就将 /etc/anisble/ansible.cfg中的action_plugins ={ceph-ansible中的actions路径}

    参考1

    参考2

完成

image-20210217155314817
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值