Articles of ansible

像Ansible这样的厨师dynamic库存?

在Ansible中,我可以使用shell脚本来提供要configuration的主机列表,在Chef中,我知道Chef Server提供了类似的function。 不过,我不想安装一个沉重的服务器来提供这个function,是否有任何解决方法,所以我可以在像Ansible这样的厨师做类似的事情?

Ansible – 获取要应用的angular色列表,并命令应用程序

我们的团队广泛使用Ansible在“静态”基础架构(例如,长期居住的VM)和dynamic(例如AWS AMI)上进行部署。 我们的利益相关者已经开始要求的交付成果之一就是获得所有适用于特定目标的Ansible Roles的列表。 他们既想要应用的显式angular色,又想要被拉的任何依赖关系。 例如,假设我们在我们的操作手册中应用了3个angular色(括号中标注了依赖关系): role: – java (InternalCertificate) – httpd (OpenSSL) – application (PostgreSQL, tmpwatch, keyconfig) 希望能够得到所有这些列表以及它们将在目标节点上应用的顺序 – 例如: Applied roles: – InternalCertificate – java – OpenSSL – httpd – keyconfig – tmpwatch – PostgreSQL – application 我知道我可以从我的信息库中的信息中parsing这个信息,但是Ansible显然必须在执行时自己弄清楚这些东西,所以我试图理清如果我可以在不使用自定义代码的情况下默认转储。 谢谢。

WSGI每次请求后重新启动我的应用程序

在Apache和mod_wsgi下运行的Django应用程序在每个Ansible剧本执行后重新开始。 我的要求是运行多个playbooks并行运行。 后台线程(在服务器启动时创build)从文件系统中select一个可用的播放,并提交给一个线程池,以便并行运行 我的应用程序configuration如下所示: <VirtualHost *:1234> SSLEngine On SSLCertificateFile <path to cert file> SSLCertificateKeyFile <path to key file> ServerName example <Location /> SSLRequireSSL </Location> WSGIDaemonProcess myapp user=user group=user WSGIProcessGroup myapp WSGIScriptAlias / /home/user/test-wsgi.py CustomLog /var/log/myapp/access.log vhost_combined </VirtualHost> 我的脚本flie import os import sys import site # Add the site-packages of the chosen virtualenv to work with […]

Ansible遍历列表和数组mixin

我目前正在努力工作,将创build两个不同服务的目录,但我一直在解决如何使用可靠的循环,我想这样做。 这是对象: obj: metadata: uuid: version: services: – server: archive: binary.tar.gz dirs: bindir: /path/to/bindir/ confdir: /path/to/confdir/ tmpdir: /path/to/tmpdir/ – client: archive: binary.tar.gz dirs: tmpdir: /path/to/tmpdir 这是我的相关任务: #Creating directories – name: Creating directories for server and client mode. file: path: "{{ item.1.dirs['tmpdir'] }}" state: directory owner: "{{ item.0.metadata.uuid }}" group: "{{ item.0.metadata.uuid }}" mode: 0750 with_subelements: […]

Ansible不能SSH进入Vagrant Box

只是玩Ansible和stream浪汉。 我创build了这个小Vagrantfile: # -*- mode: ruby -*- # vi: set ft=ruby : # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure("2") do |config| # The most common configuration […]

无可奈何的检查一个目录

我有一个安装nfs份额的可靠的手册。 它首先确保目标目录存在: – name: create /mnt/tmp file: path=/mnt/tmp recurse=yes state=directory – name: mount nfs mount: src=10.0.0.2:/data/apache/htdocs name=/mnt/tmp fstype=nfs fstab=/etc/fstab state=mounted opts="user,rw,hard,intr,auto" 这个工作正常,我第一次运行的剧本,但如果我重新运行它挂在create /mnt/tmp任务。 我做错了吗? 我如何debugging问题? 我把剧本改成了这个,而这个问题用一种相当不合理的方式“解决”了: – name: check if /mnt/tmp exists stat: path=/mnt/tmp register: p – name: create /mnt/tmp when: not p.stat.exists file: path=/mnt/tmp recurse=yes state=directory – name: mount nfs mount: src=10.0.0.2:/data/apache/htdocs name=/mnt/tmp fstype=nfs […]

Ansible:pipe理员多个用户使用SSH身份validation

我可以使用一些指导。 我有一个安装有Ansible的Admin Box,需要使用SSH身份validation在多个系统上创build用户。 我创build我的SSH密钥,将密钥添加到Ansible Playbook,当我执行剧本时,它会在pipe理员Box和远程服务器上创build用户,并将密钥复制到远程服务器。 这只能在root用户下打开SSH身份validation 下面,显示用户“Ansible”已经创build,并且在Admin Box和Remote Server上都创build了用户。 它也复制了密钥。 但是,我无法使用SSH身份validation进行身份validation。 AdminBox:CentOS Linux版本7.3.1611(核心) – 10.6.16.235 [ansible@SELC01 ~]$ ls /etc/ansible/pub_key/ ansible ansible.pub [ansible@SELC01 ~]$ cat /etc/ansible/pub_key/ansible.pub ssh-rsa AAAAB3NzaC1yc2EA…..Qys0/V ansible@localhost [ansible@SELC01 ~]$ [ansible@SELC01 ~]$ cat /home/ansible/.ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EA…..Qys0/V ansible@localhost [ansible@SELC01 ~]$ [ansible@SELC01 ~]$ groups ansible root wheel [ansible@SELC01 ~]$ cat /home/ansible/.ssh/known_hosts… 10.6.16.106 ecdsa-sha2-nistp256 AAAAE2VjZHNh….. 服务器:CentOS Linux版本7.3.1611(核心) – […]

SSH密钥连接失败时如何告诉Ansible提示用户密码?

我和一群害怕linux的networking工程师一起工作,我正在为我的团队创build一个无缝的用户体验。 如何创build一个条件:当密钥validation失败时,提示用户input用户名和密码? 这是我迄今为止: — – name: Get facts from core1.site1 Junos router hosts: routers connection: local gather_facts: no roles: – Juniper.junos vars_prompt: – name: netconf_user prompt: Username private: no – name: netconf_password prompt: Password private: yes register: results vars: default_port: 830 tasks: – name: Get Junos Facts junos_get_facts: host: "{{ inventory_hostname }}" ######I would like […]

使用Ansible访问ESXI(python)

我想要在远程ESXi上使用Ansible执行一个命令,但似乎没有grp模块。 # ansible esxi -a "date" esxi | FAILED >> { "failed": true, "msg": "Traceback (most recent call last):\r\n File \"//.ansible/tmp/ansible-tmp-1409770903.88-199403044644009/command\", line 229, in <module>\r\n import grp\r\nImportError: No module named grp\r\n", "parsed": false } 我试图将这些模块从另一个主机复制到ESXi的python lib文件夹,但它也没有工作。 有没有办法让它工作,或者我应该尝试为ESXi编译更新版本的Python?

Ansible SSH作为一个用户,而Sudo作为另一个用户

我在configurationAnsible和sudo时遇到问题,无法让SSH进入服务器并以另一个用户身份运行命令。 我已经通过下面的问题/答案和Ansible文档在这里: http ://docs.ansible.com/intro_inventory.html 但我仍然无法工作。 请有人把我放在正确的轨道上。 参考文献: https://stackoverflow.com/questions/24743085/ansible-ssh-as-one-user-and-sudo-as-another Ansible:使用不同的sudo用户为不同的主机 我正在尝试这样做: server-01 client-01 ——— ———– foo —-> ssh —> foo bar – sudo as root user 使用Ansible,从:server-01连接到:client-01 使用用户foo,然后使用sudo运行命令作为用户栏用户栏设置为可以运行任何命令。 但是,我不确定问题在哪里,用sudo或Ansible。 我认为问题是与sudo,但我不知道在哪里。 这个可靠的命令起作用: [foo@server-01 ~]$ **ansible client-01 -m raw -a "touch /var/tmp/testfile" –ask-sudo-pass** sudo password: ********* ( password for foo user ) client-01 | success | rc=0 >> […]