ansible

Ansible, set_fact using if then else statement

隐身守侯 提交于 2020-01-12 08:04:06
问题 I am trying to set a variable in Ansible with set_fact at runtime based upon another variable. If uses first value no matter what the actual value is. Here is my code example: - name: Global_vars - get date info set_fact: jm_env: "{{lookup('env', 'Environment')}}" l_env: "{% if '{{jm_env}}==Develop' %}d{% elif '{{jm_env}}==Staging'%}s{% else %}p{% endif %}" l_env is d no matter what jm_env is set. 回答1: Firstly, dictionaries in YAML are not ordered (and the syntax used by Ansible here is a

Is there a way to have both encrypted and nonencrypted host vars?

北城以北 提交于 2020-01-12 07:23:51
问题 If I encrypt host_vars/* files with ansible-vault , I don't seem to have a chance to have nonencrypted host vars other than those residing in the inventory file. Am I missing something? 回答1: As it turns out, host_vars - and group_vars -files might be directories in actuality. That is, instead of creating host_vars/example.com one might create host_vars/example.com/vault and host_vars/example.com/vars . All the files residing in the directory are read. Which settles it. Additionally, the best

Ansible安装配置(linux客户端)

强颜欢笑 提交于 2020-01-12 06:53:21
yum安装 yum install epel-release -y yum install ansible –y ansible配置文件 inventory = /etc/ansible/hosts1 这个参数表示资源清单inventory文件的位置,资源清单就是一些ansible需要连接管理的主 机列表。这个参数的配置实例如下: library = /usr/share/ansible1 ansible的操作动作,无论是本地或远程,都使用一小段代码来执行,这小段代码称为模块,这个library参数就是指向存放ansible模块的目录。配置实例如下: ansible支持多个目录方式,只要用冒号“ : ”隔开就可以,同时也会检查当前执行playbook位置下的./library目录。 forks = 51 设置默认情况下ansible最多能有多少个进程同时工作, 从ansible 1.3开始,fork数量默认自动设置为主机数量或者潜在的主机数量,默认设置最多5个进程并行处理。具体需要设置多少个,可以根据控制主机的性能和被管节点的数量来确定,可能是 50或100。默认值5是非常保守的值。 sudo_user = root1 这是设置默认执行命令的用户,也可以在playbook中重新设置这个参数。配置实例如下: remote_port = 221 这是指定连接被管节点的管理端口

Save temporary ansible shell scripts instead of deleting

送分小仙女□ 提交于 2020-01-12 04:02:14
问题 I noticed Ansible removes the temporary script using a semi-colon to separate the bash commands. Here is an example command: EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/Users/devuser/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 build /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ec2

Ansible doesn't pick up group_vars without loading it manually

依然范特西╮ 提交于 2020-01-11 19:56:43
问题 In my local.yml I'm able to run the playbook and reference variables within group_vars/all however I'm not able to access variables within group_vars/phl-stage . Let's assume the following. ansible-playbook -i phl-stage site.yml I have a variable, let's call it deploy_path that's different for each environment. I place the variable within group_vars/< environment name > . If I include the file group_vars/phl-stage within vars_files it works but I would've thought the group file would be

How do I exit Ansible playbook without error on a condition

我的梦境 提交于 2020-01-11 17:14:13
问题 I want to exit without an error (I know about assert and fail modules) when I meet a certain condition. The following code exits but with a failure: tasks: - name: Check if there is something to upgrade shell: if apt-get --dry-run upgrade | grep -q "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded"; then echo "no"; else echo "yes"; fi register: upgrading - name: Exit if nothing to upgrade fail: msg="Nothing to upgrade" when: upgrading.stdout == "no" 回答1: In Ansible 2.2, you can

Ansible with “Alternative Directory Layout” and using vaults

江枫思渺然 提交于 2020-01-11 12:38:25
问题 I am trying to use the Alternative Directory Layout and ansible-vaults within. But when i run my playbook, variables which are vault encrypted could not resolve with that directory structure. So what iam doing wrong? I execute via: ansible-playbook -i inventories/inv/hosts playbooks/inv/invTest.yml --check --ask-vault Here is my structure: . ├── inventories │ ├── inv │ │ ├── group_vars │ │ │ ├── var.yml │ │ │ └── vault.yml │ │ └── hosts │ └── staging │ ├── group_vars │ │ ├── var.yml │ │ └──

Ansible best practice for passing vars to nested playbooks?

点点圈 提交于 2020-01-11 10:14:49
问题 So I am trying to wrap my head around Ansible and building a simple LEMP stack. I decided to work with a nested playbook because I want to compartmentalize as much as possible, while learning. I run in to this issue where I need to pass some variables such as the root password of mysql. Now I wonder if there is any best practice passing varibles from the main playbook down to the individual plays or should the varibles be set in the individual sub-playbooks? I am using this repo as a basis

ansible变量引用

早过忘川 提交于 2020-01-11 08:50:03
在/etc/ansible/hosts默认文件中定义变量 [test] 192.168.163.130 #[test:vars] #key=ansible 或者 192.168.163.130 key=ansible [test] 192.168.163.130 编写var.yaml文件 hosts: test gather_facts: False tasks: - name: display Host Variable from hostfile debug: msg=“The {{ inventory_hostname }} Vaule is {{ key }}” ansible-playbook var.yaml #检查yaml文件语法 3. 在/etc/ansible下新建目录host_vars 写入变量文件名要以主机ip或者绑定的host命名 cat host_vars/192.168.163.130 key: 192.168.163.130 ansible-playbook var.yaml 4. 针对主机组设置变量 在/etc/ansible下新建group_vars 变量文件以主机组命名 cat group_vars/test && rm -rf host_vars key: abcdefg 5. 手动传入变量,可传入多个变量 ansible-playbook

Ansible template adds 'u' to array in template

不打扰是莪最后的温柔 提交于 2020-01-10 14:09:47
问题 I have the following vars inside of my ansible playbook I got the following structure domains: - { main: 'local1.com', sans: ['test.local1.com', 'test2.local.com'] } - { main: 'local3.com' } - { main: 'local4.com' } And have the following inside of the my conf.j2 {% for domain in domains %} [[acme.domains]] {% for key, value in domain.iteritems() %} {% if value is string %} {{ key }} = "{{ value }}" {% else %} {{ key }} = {{ value }} {% endif %} {% endfor %} {% endfor %} Now when I go in the