ansible-playbook

Search Dictionary Values in Ansible

白昼怎懂夜的黑 提交于 2019-12-24 01:03:53
问题 Having a dictionary like this: ossec_datacenter: atlanta: hostname: 'server1.fakedomain.net' ip: '192.168.12.170' port: '1515' miami: hostname: 'server2.fakedomain.net' ip: '192.168.20.31' port: '1514' dallas: hostname: 'server2.fakedomain.net' ip: '192.168.20.20' port: '1515' How would I search for all values in this dictionary in my when clause? I can access variables using ossec_datacenter[ossec_dc]['hostname'] But I want so search all values to make sure no matches are present. In other

How to process a command asking for inputs with an Ansible task?

旧街凉风 提交于 2019-12-24 00:23:43
问题 I'm learning Ansible and I'm wondering how to write a task to process the following command: $<command> <options> username: email address: password: password (check): The <command> <option> asks for four variables that can be hardcoded in the playbook. Thank you for any insight you can provide 回答1: Use expect module: - hosts: localhost tasks: - expect: command: command option responses: username: "John Doe" email: "joh@doe.com" password: "mypass" 来源: https://stackoverflow.com/questions

Generating tuples variables in ansible templates

╄→гoц情女王★ 提交于 2019-12-23 19:08:16
问题 I'm trying to setup a playbook to deploy an influxdb cluster. Everything works fine except that we use INfluxDB Cluster Client I am generating a production.py file which is read by our script. InfluxdbClusterClient is waiting for a tuple to list all influx servers : 'hosts': [('fr-influxdb-prod-1', 8086), ('fr-influxdb-prod-2', 8086), ('fr-influxdb-prod-3', 8086)], I am trying to generate those tuples from ansible variables but I don't know how to to dat. I tried: / Variables / influxdb_hosts

how to unset http_proxy in ansible playbook

不打扰是莪最后的温柔 提交于 2019-12-23 13:27:14
问题 In most ansible example, it is to set environment like setting http_proxy below, see http://docs.ansible.com/playbooks_environment.html - hosts: all tasks: - apt: name=cobbler state=installed environment: http_proxy: http://proxy.example.com:8080 In my case, I need this http_proxy in system shell, while I want to disable this in playbook, how can I achieve this ? If I work in shell, I can use unset http_proxy 回答1: You could temporarily disable the proxy for the host(s) or URL you wanted to

Ansible prompts password when using synchronize

匆匆过客 提交于 2019-12-23 06:55:07
问题 I'm using ansible in the following way: ansible-playbook -f 1 my-play-book.yaml --ask-pass --ask-sudo-pass After this I'm asked to enter the ssh & sudo passwords (same password for both). Inside my playbook file I'm using synchronize task: synchronize: mode=push src=rel/path/myfolder/ dest=/abs/path/myfolder/ For each host, I'm prompted to enter the ssh password of the remote host (the same that I entered in the beginning of the playbook run) How can I avoid entering the password when

Ansible loop using multi-ter group_vars

穿精又带淫゛_ 提交于 2019-12-23 02:54:15
问题 I'm trying to dynamically create templates in ansible using group_vars but cannot seem to get the nested loop working. In group_vars, I have my_environment: serv1: foo: 2 bar: 3 baz: 3 serv2: foo: 1 I'm trying to create the following structure: /serv1/foo1 /serv1/foo2 /serv1/bar1 /serv1/bar2 /serv1/bar3 /serv1/baz1 /serv1/baz2 /serv1/baz3 /serv2/foo1 Once the above is created, I want to put a template file into each directory so the final result would be: /serv1/bar1/template and /serv2/foo1

How to add a callback plugin to a PlaybookExecutor in Ansible 2

爷,独闯天下 提交于 2019-12-22 09:27:12
问题 How to specify a callback when calling ansible via its API? I have a callback plugin database_write.py for ansible 2.0.0.2 that logs into a database when this is run: ansible-playbook -i inventory.txt playbook.yml # callback is fired ok This works ok because in my $PWD i have ansible.cfg with this line: callback_plugins = ./src/callback Now I'm trying to make ansible to execute my playbook and my callback using the python API. I've basically copied what the ansible-playbook cli tool does #

How to log in a separate file per playbook in Ansible

落花浮王杯 提交于 2019-12-21 20:13:07
问题 Instead of the single log file defined in log_path, I want to have separate log files per playbook run in Ansible. As far as I know there is no built-in way to do that. So I am looking for clever "hacks". More specifically, I want after a playbook is ran a log file to be generated in the format [playbook name].[date].log I found this thread in SO but it doesn't meet my needs. The alias would be a solution if I could pass somehow the playbook name dynamically, not only the date. The lookup

How to remove user from a specified group in Ansible?

南笙酒味 提交于 2019-12-21 18:31:14
问题 Let's assume user01 has two groups defined: groupA and groupB (in addition to the primary group). I can add the account to groupC (ensure user01 belongs to groupC ) using: - user: name=user01 groups=groupC append=yes How can I remove user01 from groupB (ensure user01 does not belong to groupB ) without specifying all the groups the account should belong to? 回答1: As far as I can tell, you can't with just the normal user module. However, with some fairly crazy gyrations, you can do it in a

Cannot get ansible to recognize group variables

霸气de小男生 提交于 2019-12-21 17:43:57
问题 I'm trying to set up environment specific variables in ansible (e.g. production, staging, development). For some reason, ansible is not picking up variables in group_vars/[environment]. I'm using ansible 1.9.1 Here's a stripped down example of what I'm trying to do. Directory structure: . ├── group_vars │ └── staging ├── hosts │ └── staging └── site.yml group_vars/staging: test_var: "this is a test" site.yml: --- - hosts: localhost tasks: - debug: msg="test variable = {{ test_var }}" hosts