ansible tower 的搭建

Linux Ansible ansible tower 的搭建 下载 axel https://releases.ansible.com/ansible-tower/setup-bundle/ansible-tower-setup-bundle-3.7.3-1.tar.gz -n 10 可能会出现:重定向过多 的问题,手动编译 axel 或者使用 wget 即可。 # 下载源码包 wget -O axel-2.16.1.tar.gz https://file.idait.cn/axel-2.16.1.tar.gz # 解压 tar xzvf axel-2.16.1.tar.gz # 进入目录 cd axel-2.16.1/ # 检查编译 ./configure --prefix=/usr/local/axel # 报错 No package 'openssl' found,则 yum install openssl-devel make && make install #报错请安装 gcc 工具 不报错请忽略 yum groupinstall "Development tools" #axel 执行路径 echo 'PATH=/usr/local/axel/bin:$PATH' > /etc/profile.d/axel.sh #使文件生效 . /etc/profile 配置并安装 cd /opt/ tar xf ansible-tower-setup-bundle-3.7.3-1.tar.gz cd ansible-tower-setup-bundle-3.7.3-1/ # 配置密码 vim inventory [tower] localhost ansible_connection=local [database] [all:vars] admin_password='abcdefg' pg_host='' pg_port='' pg_database='awx' pg_username='awx' pg_password='abcdefg' # 安装 ./setup.sh 破解 # 安装 pip cd /tmp axel https://bootstrap.pypa.io/get-pip.py -n 10 python get-pip.py # 安装 uncompyle6 pip install uncompyle6 cd /var/lib/awx/venv/awx/lib/python3.6/site-packages/tower_license ls -al 总用量 12 -rw-r--r-- 1 root root 8348 9月 28 16:00 __init__.pyc drwxr-xr-x 2 root root 37 11月 15 04:02 __pycache__ # 反汇编 init.pyc uncompyle6 __init__.pyc >__init__.py # 修改 __init__.py 文件 def _check_cloudforms_subscription(self): return True #添加这一行 if os.path.exists('/var/lib/awx/i18n.db'): return True else: if os.path.isdir('/opt/rh/cfme-appliance'): if os.path.isdir('/opt/rh/cfme-gemset'): pass try: has_rpms = subprocess.call(['rpm', '--quiet', '-q', 'cfme', 'cfme-appliance', 'cfme-gemset']) if has_rpms == 0: return True except OSError: pass return False .... # 修改 "license_date=253370764800L" 为 "license_date=253370764800" def _generate_cloudforms_subscription(self): self._attrs.update(dict(company_name='Red Hat CloudForms License', instance_count=MAX_INSTANCES, license_date=253370764800, #修改 license_key='xxxx', license_type='enterprise', subscription_name='Red Hat CloudForms License')) ... #------------------------------------------------------------------ #修改完重新编译一下 [root@tower tower_license]# python3 -m py_compile __init__.py [root@tower tower_license]# python3 -O -m py_compile __init__.py #重启服务 [root@tower tower_license]# ansible-tower-service restart

ansible vault 的使用

Linux Ops Ansible ansible vault 的使用 ansible 在某些特殊的操作,例如 become 提取操作,再或者有些配置文件有机密信息,不想明文保存,那么就需要用到 vault 这个工具。它随着 ansible 发行,调用方式为 ansible-vault。 在不是非常保密严格的场合,可以只配置 2-3 个 vault 密码,去加密 ansible 用到的所有文件。 现在假设当前目录下有以下文件: ansible.cfg hosts hello.yml 那么除了 ansible.cfg 不能被加密,其他数据都可以加密。相当于用一个密码隐藏另一堆机密数据。 模块说明 create: 创建一个新文件,并直接对其进行加密 decrypt: 解密文件 edit: 用于编辑 ansible-vault 加密过的文件 encrypy: 加密文件 encrypt_strin: 加密字符串,字符串从命令行获取 view: 查看经过加密的文件 rekey: 重新设置密码 每个模块都很容易理解。 每个模块的作用可以参考: ansible笔记(43):使用 ansible-vault 加密数据 Ansible 加密模块 Vault 使用方式 这里提供两种加密明文密码的使用姿势。 首先,我们需要创造一个 vault 的密码,这个密码可以人工创造,或者交给 openssl 自动生成,存储在特定文件里。 $ openssl rand -base64 100 > vault.pass 接着编辑 ansible.cfg 文件(该文件绝不能被 vault 加密)。 ...

ansible 运行持续进程及配置环境变量

Linux Ops Ansible ansible 运行持续进程及配置环境变量 配置环境变量 ansible 是通过 ssh 登陆的,同时也是 Non-Login 的方式登陆,这种登陆情况下,部分环境参数是拿不到的。Login 和 Non-Login 的区别可以参考 Difference between Login shell and Non login shell。 那么如果一行 shell 运行的指令需要用到环境参数该怎么处理? 根据 Non-Login shell 调用顺序,~/.bashrc 是会被调用的,所以可以想办法把参数文件写在 ~/.bashrc 中,这样就可以运行 shell。 另一种思路是,不想破坏系统的 ~/.bashrc 文件,或者环境变量本身也是经常变的,那么就自制一个文件,通过 source 启用,设想很好,但是实际操作不行,我这边的环境(ubuntu 18.04 server)提示 source:command not found。有些解释是,ansible 的 shell 不是 bash,没有 bash 的特性。 但 source 的方法不行,还有另一个方法,启用 environment。 --- - hosts: all remote_user: test gather_facts: True tasks: # 在需要环境的任务下,一一指定变量,在执行过程中会导入这些变量 - name: some command need environment shell: cmd: xxx yyy zzz chdir: /your/path environment: ARGS1: 1 ARGS: 2 后台持续运行 后台持续运行的方法很多,正规点的利用 supervisord,systemd 配置一个服务,让服务在后台运行,但这需要配置文件,有没有更好的处理方法,nohup 能否在 ansible 中使用,答案是:可以。 ...