ansible

How check a file exists in ansible?

不羁岁月 提交于 2019-12-29 11:32:42
问题 I have to check whether a file exists in /etc/ . If the file exists then I have to skip the task. Here is the code I am using: - name: checking the file exists command: touch file.txt when: $(! -s /etc/file.txt) If the file.txt exists then I have to skip the task. 回答1: You can first check that the destination file exists or not and then make a decision based on the output of it's result. tasks: - name: Check that the somefile.conf exists stat: path: /etc/file.txt register: stat_result - name:

How check a file exists in ansible?

流过昼夜 提交于 2019-12-29 11:31:14
问题 I have to check whether a file exists in /etc/ . If the file exists then I have to skip the task. Here is the code I am using: - name: checking the file exists command: touch file.txt when: $(! -s /etc/file.txt) If the file.txt exists then I have to skip the task. 回答1: You can first check that the destination file exists or not and then make a decision based on the output of it's result. tasks: - name: Check that the somefile.conf exists stat: path: /etc/file.txt register: stat_result - name:

using regex in jinja 2 for ansible playbooks

大兔子大兔子 提交于 2019-12-29 05:56:32
问题 HI i am new to jinja2 and trying to use regular expression as shown below {% if ansible_hostname == 'uat' %} {% set server = 'thinkingmonster.com' %} {% else %} {% set server = 'define yourself' %} {% endif %} {% if {{ server }} match('*thinking*') %} {% set ssl_certificate = 'akash' %} {% elif {{ server }} match( '*sleeping*')%} {% set ssl_certificate = 'akashthakur' %} {% endif %} based on the value of "server" i would like to evaluate as which certificates to use. ie if domain contains

Using ansible to manage disk space

扶醉桌前 提交于 2019-12-29 05:19:11
问题 Simple ask: I want to delete some files if partition utilization goes over a certain percentage. I have access to "size_total" and "size_available" via "ansible_mounts". i.e.: ansible myhost -m setup -a 'filter=ansible_mounts' myhost | success >> { "ansible_facts": { "ansible_mounts": [ { "device": "/dev/mapper/RootVolGroup00-lv_root", "fstype": "ext4", "mount": "/", "options": "rw", "size_available": 5033046016, "size_total": 8455118848 }, How do I access those values, and how would I

Is there with_fileglob that works remotely in ansible?

为君一笑 提交于 2019-12-28 16:31:58
问题 Is there with_fileglob that works remotely in ansible? Mainly I do want to use something similar with the with_fileglob but that will glob the files on the remote/target machine, not on the one that is running ansible. 回答1: All of the with_* looping mechanisms are local lookups unfortunately so there's no really clean way to do this in Ansible. Remote operations by design must be enclosed in tasks as it would need to deal with connections and inventory etc. What you can do is generate your

ansible批量自动部署Nginx

六眼飞鱼酱① 提交于 2019-12-28 16:15:47
[root@node1 file]# tree . ├── hosts ├── install.yml └── roles ├── common │ └── tasks │ └── main.yml └── nginx ├── files │ └── nginx-1.12.2.tar.gz ├── tasks │ └── main.yml ├── templates └── vars └── main.yml 8 directories, 6 files ]#vim hosts [node] node1 ansible_ssh_user=root ansible_ssh_pass=xxxx node2 ansible_ssh_user=root ansible_ssh_pass=xxxx node3 ansible_ssh_user=root ansible_ssh_pass=xxxx node4 ansible_ssh_user=root ansible_ssh_pass=xxxx node5 ansible_ssh_user=root ansible_ssh_pass=xxxx node6 ansible_ssh_user=root ansible_ssh_pass=xxxx ]# vim install.yml hosts: node gather_facts: no

Ansible模块整理

故事扮演 提交于 2019-12-28 14:22:26
Ansible模块整理 #ping ping模块用来检查目标主机是否在线 例子:ansible webserver -m ping #yum yum模块用来在Centos系统上使用yum命令安装软件包 选项: name: 指定安装包的名字 state:latest 安装最新版 present 默认安装 installed 安装 absent 卸载 #removed 卸载 例子:ansible webservers -m yum -a ‘name=httpd state=latest’ command模块用来执行系统命令,但是不支持shell下的特殊符号 如:| &&等 #command 例子:ansible webservers -m command -a ‘echo 李想’ #shell shell模块和command模块使用方法基本一致,但是他可以支持shell的特殊符号,如: | && 等 例子:ansible webservers -m shell -a “cd /opt/ && touch lixiang” #service service模块用来管理centos上的服务的启动、关闭、重启和重载 选项: name: 服务名字 state: started(启动) stopped(停止) restarted(重启) reloaded(重载) enabled: 默认是no

ansible安装nginx

痴心易碎 提交于 2019-12-28 13:51:26
ansible安装nginx #定义一个ansible组,把nginx.tar包传到ansible主机 ansible 组名 - m shell - a "yum - y install pcre - devel open - devel gcc gcc - c++" #nginx依赖 ansible 组名 - m unarchive - a "src=/root/nginx.tar.gz dest=/usr/local/" #解压至ansible对应主机 ansible 组名 - m shell - a "cd /usr/local/nginx.tar.gz && ./configure && make && make install" #需改nginx名称,编译环境,安装 来源: CSDN 作者: wangzihao-sxm 链接: https://blog.csdn.net/qq_45019159/article/details/103743008

Filter object by property and select with key in jmespath

我是研究僧i 提交于 2019-12-28 13:50:27
问题 I'm trying to filter properties of an object in jmespath based on the value of a subproperty and want to include only those properties where the subproperty is set to a specific value. Based on this example data: { "a": { "feature": { "enabled": true, } }, "b": { }, "c": { "feature": { "enabled": false } } } I'd like to get an object with all properties where the feature is enabled. { "a": { "feature": { "enabled": true, } } } I figured I could use this jmespath query to filter the objects

ansible wget then exec scripts => get_url equivalent

不羁岁月 提交于 2019-12-28 13:47:53
问题 I always wonder what is the good way to replace the following shell tasks using the "ansible way" (with get_url , etc.): - name: Install oh-my-zsh shell: wget -qO - https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash - or - name: Install nodesource repo shell: curl -sL https://deb.nodesource.com/setup_5.x | bash - 回答1: This worked for me: - name: Download zsh installer get_url: url=https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh dest=/tmp/zsh