Ansible中的库存variables可以依赖于事实吗? 也就是说,我在group_vars/all/cars.yml中有一个variables,我想设置一个依赖于ansible_fqdn的值。 喜欢: — 链接:“http:// {{ansible_fqdn}}:8070 / api” 我已经尝试过,它有时似乎工作,有时甚至没有,给我的文字ansible_fqdnexpression而不是替代它。
有没有一个模块,能够安装吞噬文件,如可能为NPM : description: Install "coffee-script" node.js package. – npm: name=coffee-script path=/app/location description: Install "coffee-script" node.js package on version 1.6.1. – npm: name=coffee-script version=1.6.1 path=/app/location description: Install "coffee-script" node.js package globally. – npm: name=coffee-script global=yes description: Remove the globally package "coffee-script". – npm: name=coffee-script global=yes state=absent description: Install "coffee-script" node.js package from custom registry. – npm: […]
我想运行一个任务,使用with_items填充参数,而不必手动写入parameter:{{item.key}} 。 例如,我有这个主机var: HtpasswdsToSet: – path: /etc/nginx/passwdfile name: janedoe password: 'abc123' – path: /etc/nginx/passwdfile name: bob password: '123abc' 请注意 ,字典列表键是实际的htpasswd任务参数。 在剧本中,而不是这样做: – name: add htpasswd users htpasswd: path: {{item.path}} name: {{item.name}} password: '{{item.password}}' with_items: "{{HtpasswdsToSet}}" 有没有办法简单地做到这一点? – name: add htpasswd users htpasswd: "{{HtpasswdsToSet}}" 这真的会帮助我减less剧本的冗长。 谢谢。
在我尝试更换几年前build立的Linux服务器时,我意识到没有人知道自从安装/configuration了什么。 我在git唯一的东西是nginx的网站定义。 我有什么select来比较正在运行的服务器和干净的安装? 我想使用Ansible进行版本化configurationpipe理,但在此之前,我需要获得有关已安装服务及其configuration文件,防火墙规则,用户/组,SSH密钥,域设置等信息,我甚至不知道该怎么做考虑到。 我可以看到一个/data文件夹,所以这很简单,但它包含www数据, nodejs数据和nodejs应用程序,这意味着安装了一个node nodejs和nodejs 。 我发现Jenkins安装的痕迹,但没有运行。 我可以看到一个fail2ban服务,所以这也需要移动。 有什么方法可以看到自初始设置以来发生了什么变化? 我想用一个干净的16.04replace这个Ubuntu 14.04使用Ansible的手册,以避免这种混乱,也许dockerize一些服务,同时保留目前的function。
我正在更换我们的DNS服务器。 作为其中的一部分,我们静态configuration的服务器接口的DNS条目需要更新。 但是,我遇到了一个障碍。 接口目前有2个条目定义,我想用3replace它们。 这个剧本演示了使用replace的问题。 它将取代DNS1和DNS2,但不能添加DNS3。 lineinfile有类似的问题。 — – hosts: canary vars: nameservers: [ '', 192.0.2.1, 192.0.2.2, 192.0.2.3 ] tasks: – name: nameservers replace: path: /etc/sysconfig/network-scripts/ifcfg-{{ansible_default_ipv4.interface}} replace: \1="{{ item.1 }}" regexp: (DNS{{ item.0 }}).+ with_indexed_items: – "{{ nameservers }}" when: ansible_distribution == "CentOS" and "nameservers" not in group_names tags: – debug
我有一些nginxconfiguration片段,它添加位置,即发送请求到特定的path到fastcgi服务器。 对于一个干净的部署,我想使用/etc/nginx/conf.d文件夹将它们添加到那里。 问题是, location /something属于服务器块,默认服务器已经在/etc/nginx/sites-enabled/default 。 而当我想部署更多不同的位置时,他们不应该为每个包含需要一个自己的虚拟主机。 可能甚至一个网站sites-enabled将是有用的,但它应该仍然是可组合的。 在不知道是否安装了其他代码片段的情况下,可以在同一个configuration中包含不同的片段。 有没有一种干净的方式来包含configuration片段的位置块,而无需修改默认configuration?
这是寄存器的内容来自: – debug: var: vmfacts.virtual_machines ok: [localhost] => { "vmfacts.virtual_machines": { "2k12r2-k11": { "guest_fullname": "Microsoft Windows Server 2012 (64-bit)", "ip_address": "10.0.1.20", "mac_address": [ "00:50:56:00:00:20" ], "power_state": "poweredOn", "uuid": "421d5210-8a64-2d60-8b44-02de952600d1" }, 下面的工作正常,但我需要从上面的uuid的价值 – shell: "echo {{ item }}" with_items: "{{ vmfacts.virtual_machines }}" 似乎无法解码的语法,这些似乎没有工作: “echo {{item.uuid}}”“echo {{item.0.uuid}}”“echo {{item [0] .uuid}}” 访问uuid值的正确方法是什么?
我有一些我希望delegate_to某些主机的任务(最后我想列出他们在一些变种,而不是从库存使用组)。 对于这个问题,让简化(我做了完全一样的希望,它会帮助我发现问题的地方): – name Foo tamplate: dest=/path/to/file src=template.j2 delegate_to: "{{ item }}" with_items: – some.host.in.my.domain 这引发了一个exception: Exception: host not found: {{ item }} 任何想法,为什么这是行不通的? 让我知道你是否需要更多的细节。 预先感谢您的帮助。
我有一个angular色,从git更新我的项目的源代码,让我们把它命名为source_tree 。 Git仓库包含多个服务使用的源,所以如果检测到git的变化,我想重新启动在每个主机上使用该源的所有服务 。 即: – git: repo=ssh://[email protected]/mylogin/hello.git dest=/home/mylogin/hello notify: restart everything dependent on source code 例如,我有angular色webapp , notification_service , celery 。 主机可以有任何一组这样的angular色,例如第一台服务器运行webapp ,第二台运行notification_service和celery 。 所有这些服务使用来自同一目录的源代码。 问题是: 我不能列出所有的处理程序notify如: – git: repo=ssh://[email protected]/mylogin/hello.git dest=/home/mylogin/hello notify: – restart webapp – restart notification service – restart celery 因为如果我运行不具有所有angular色的playbook(或者即使主机不包括所有angular色),playbook也会失败,并显示错误: ERROR: change handler (restart celery) is not defined (即我有webapp.yml手册,其中包括source_tree和webappangular色,但不包括notification_service和celery 。) 而且没有办法忽略这个错误。 […]
我试图设置Ansible来pipe理来自不同客户的Linux机器,这里是我们必须要处理的。 没有酒吧的钥匙authentication – 我想和你一样多,但不会很快发生。 我们以root身份login,每个客户对所有Linux机器都有不同的root密码。 我们正在推动禁用直接rootlogin,并通过sudo做所有事情,但是再次,这将需要一些时间。 我设法为每个客户创build一个ansible_ssh_user和ansible_ssh_pass库文件,并遵循好的作品。 — – hosts: – SERV01 – SERV02 vars_files: – roles/common/vault/main.yml tasks: – name: enable and start ntpd service: name=ntpd enabled=yes state=running 现在我想知道如何从命令行使用Vault文件,但以下都不起作用。 ansible customer1 -m shell -a "var_files:roles/common/vault/main.yml uptime" –ask-vault-pass ansible customer1 -m shell -a "uptime" -e "vars_files:roles/common/vault/main.yml" –ask-vault-pass 我究竟做错了什么 ? 谢谢