ansible

ansible: Is there something like with_fileglobs for files on remote machine?

混江龙づ霸主 提交于 2020-01-02 00:13:15
问题 I'm trying to turn these lines into something I can put in an ansible playbook: # Install Prezto files shopt -s extglob shopt -s nullglob files=( "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/!(README.md) ) for rcfile in "${files[@]}"; do [[ -f $rcfile ]] && ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile##*/}" done So far I've got the following: - name: Link Prezto files file: src={{ item }} dest=~ state=link with_fileglob: - ~/.zprezto/runcoms/z* I know it isn't the same, but it would select the same

Ansible基础入门1

痴心易碎 提交于 2020-01-01 23:48:25
常用自动化运维工具: Ansible:python,Agentless,中小型应用环境 Saltstack:python,一般需要部署agent,执行效率高 Puppent:ruby,功能强大,配置复杂,适合大型环境 Fabric:python,agentlees Ansible特性: 模块化:调用特定的模块,完成特定任务 有Paramiko,PyYAML,Jinja2(模板语言)三个关键模块 支持自定义模块 基于Python语言实现 部署简单,基于python和ssh,agentless 安全,基于openssh 支持playbook编排任务 幂等性:一个任务执行1遍和执行n遍效果一样,不会因为重复执行而带来意外情况 无须代理不依赖PKI(无须SSL) 可使用任何编程语言写模块 YAML格式,编排任务,支持丰富的数据结构 较强大的多层解决方案 Ansible架构: User通过主控端ansible控制host,ansbile里有一个host lnventory 主机清单记录着哪些主机是要被控制的,模块用于单一的命令,如果要执行多条任务就要用到playbook批量执行。 要连接被控制主机就要用到Connection plugins连接插件基于SSH协议来执行。不仅可以使user用户来管理,也可以利用私有云或公有云开发接口来进行管理。 Ansible工作过程: 1、加载自己的配置文件

Deploying with Docker into production: Zero downtime

杀马特。学长 韩版系。学妹 提交于 2020-01-01 19:26:29
问题 Im failing to see how it is possible to achieve zero-downtime deployments with Docker. Let's say I have a PHP container running MyWebApp being served by an Nginx container on the same server. I then change some code, as Docker containers are immutable I have to build/deploy the MyWebApp container again with the code changes. During the time it takes to do this MyWebApp is down for the count... Previously I would use Ansible or similar to do deploy my code, then symlink the new release

Ansible cannot make dir /$HOME/.ansible/cp

岁酱吖の 提交于 2020-01-01 15:37:48
问题 I'm getting a very strange error when I run ansible: GATHERING FACTS *************************************************************** fatal: [i-0f55b6a4] => Could not make dir /$HOME/.ansible/cp: [Errno 13] Permission denied: '/$HOME' TASK: [Task #1] *************************************************************** FATAL: no hosts matched or all hosts have already failed -- aborting PLAY RECAP ******************************************************************** to retry, use: --limit @/home

Nginx cannot restart via Ansible

99封情书 提交于 2020-01-01 10:54:12
问题 I have a task in a playbook that tries to restart nginx via a handler as per usual: - name: run migrations command: bash -lc "some command" notify: restart nginx The playbook however breaks on this error: NOTIFIED: [deploy | restart nginx] ******************************************** failed: [REDACTED] => {"failed": true} msg: failure 1 running systemctl show for 'nginx.service': Failed to get D-Bus connection: No connection to service manager. The handler is standard: - name: restart nginx

Nginx cannot restart via Ansible

风格不统一 提交于 2020-01-01 10:54:11
问题 I have a task in a playbook that tries to restart nginx via a handler as per usual: - name: run migrations command: bash -lc "some command" notify: restart nginx The playbook however breaks on this error: NOTIFIED: [deploy | restart nginx] ******************************************** failed: [REDACTED] => {"failed": true} msg: failure 1 running systemctl show for 'nginx.service': Failed to get D-Bus connection: No connection to service manager. The handler is standard: - name: restart nginx

Using hyphen in ansible

三世轮回 提交于 2020-01-01 09:26:07
问题 I am learning Ansible but I am getting confused when to use hyphen and when not to use hyphen in playbook. As I know, hyphen is used for list in Ansible. For example, --- # my first playbook - hosts: webservers ( why did we use hyphen here it is not a list) tasks: - name: installing httpd yum: name=httpd state=installed ( why we shouldn't use hyphen here). From Ansible documentation, it is said that hyphen is for list, for example: fruits: - apple - grapes - orange So, I am confused when to

Ansible lineinfile insertafter injects line at end of file

房东的猫 提交于 2020-01-01 09:21:48
问题 I'm using lineinfile as follows: lineinfile dest=./hosts_exp insertafter='\[hosts1\]' line="xxxxxxxxx" state=present My hosts_exp is as follows: [local] localhost [hosts1] [hosts2] [hosts3] lineinfile inserts the text after [hosts3] instead of inserting it after [hosts1]. 回答1: use: lineinfile: dest: "./hosts_exp" line: "xxxxxxxxx" insertafter: '^\[hosts1\]' state: present 回答2: example: - name: "blah" lineinfile: dest: "/test.sh" insertafter: 'test text' line: "text add" state: present 回答3: It

If condition is true run some include yml files

无人久伴 提交于 2020-01-01 08:58:45
问题 I have some playbook for ubuntu and centos and I want to use main.yml to check when: ansible_os_family == 'RedHat' or ansible_distribution == 'Centos' , run playbooks ( as some ans many :-) ). When I run just: -include: centos-xxx.yml -include: centos-xaa.yml -include: centos-xsss.yml It will run all of them Basically I want that the playbook will run if meet condition. I didn't find any doc that say how to run include: more then one i am trying to not make task per include if possible. 回答1:

ansible parse text string from stdout

我的梦境 提交于 2020-01-01 08:34:11
问题 My problem is with ansible and parsing stdout. I need to capture the stdout from an ansible play and parse this output for a specific substring within stdout and save into a var. My specific use case is below - shell: "vault.sh --keystore EAP_HOME/vault/vault.keystore | --keystore-password vault22 --alias vault --vault-block | vb --attribute password --sec-attr 0penS3sam3 --enc-dir | EAP_HOME/vault/ --iteration 120 --salt 1234abcd" register: results become: true This generates an output with