ansible-2.x

Ansible Loop and Update Dict

社会主义新天地 提交于 2021-02-11 13:53:47
问题 I'm trying to use Ansible to loop through a nested dict and add a new key:value. I'm able to add a value using combine to the top-level dict but unsure how to update the value dict. I see that loop can be used to iterate through the dict but how can update be done at the same time? My Dict {'host-a': {'os': 'Linux', 'port': '22', 'status': 'Running'}, 'host-b': {'os': 'Linux', 'port': '22', 'status': 'Running'}, 'host-c': {'os': 'Linux', 'port': '22', 'status': 'Running'}} I'm able to append

Ansible, How to modify a variable during a loop?

让人想犯罪 __ 提交于 2021-02-10 19:38:23
问题 I am using Ansible 2.3.0.0 and I have tested in Ansible 2.4.0.0, obtaining the same result. My problem is simple. I have the following list: vars: password_text_to_encrypt: - { line: "{{truststore_pass }}" , result: } - { line: "{{ keystore_pass }}" , result: } - { line: "{{ gp_pass }}" , result: } - { line: "{{ datasource_password }}" , result: } - { line: "{{ server_password }}" , result: } - { line: "{{ sftp_password }}" , result: } - { line: "{{ db_userpassword }}" , result: } roles: -

Ansible Special Characters in passwords

主宰稳场 提交于 2021-02-10 12:05:08
问题 I read my root passwords from an encrypted ansible-vault file. But when I use it on ansible_become_pass the operation fails because the password contains a special character. In my example " # " This is my yml: - hosts: sirius remote_user: ansusr become: yes vars_files: - vault_vars.yml become_pass: "{{ root_pass_sirius }}" ansible-playbook check.yml --ask-vault-pass fatal: FAILED! => {"msg": "{{ TesT#1234 }}: template error while templating string: unexpected char '#' at 6. String: {{ TesT

Ansible Special Characters in passwords

谁说胖子不能爱 提交于 2021-02-10 12:00:57
问题 I read my root passwords from an encrypted ansible-vault file. But when I use it on ansible_become_pass the operation fails because the password contains a special character. In my example " # " This is my yml: - hosts: sirius remote_user: ansusr become: yes vars_files: - vault_vars.yml become_pass: "{{ root_pass_sirius }}" ansible-playbook check.yml --ask-vault-pass fatal: FAILED! => {"msg": "{{ TesT#1234 }}: template error while templating string: unexpected char '#' at 6. String: {{ TesT

key value pair mapping in ansible to pass run the role with the appropriate value

我的梦境 提交于 2021-02-08 08:09:04
问题 I am new to ansible. I have a small scenario. So I pass the name of the branch using ansible when I run it. In my play book I have: # Deploy docker container - include_role: name: devops/deployment.docker vars: docker_name: "docker name is based on the branch id develop dev if UAT test if master then it should be prod" when: build_type in "develop master UAT" and in devops/deployment.docker I have a role which deploy a docker image. - name: push docker container docker_image: name: "{{ docker

key value pair mapping in ansible to pass run the role with the appropriate value

三世轮回 提交于 2021-02-08 08:01:32
问题 I am new to ansible. I have a small scenario. So I pass the name of the branch using ansible when I run it. In my play book I have: # Deploy docker container - include_role: name: devops/deployment.docker vars: docker_name: "docker name is based on the branch id develop dev if UAT test if master then it should be prod" when: build_type in "develop master UAT" and in devops/deployment.docker I have a role which deploy a docker image. - name: push docker container docker_image: name: "{{ docker

Ansible conditional statements not evaluating correctly

非 Y 不嫁゛ 提交于 2021-02-08 07:40:27
问题 I have an ansible playbook with a couple of tasks that check a directory for files created on todays date and saves them in files . I'm doing my comparison off of files|length and print out two different messages depending if the length is 0 or not. Here is the code: - name: Grabbing all of the files that were created today shell: find /home/user/empty_directory -maxdepth 1 -daystart -ctime 0 -print register: files - debug: var=files.stdout - debug: msg="The directory isn't empty" when: files

can't read custom facts with list (array) of items

折月煮酒 提交于 2021-02-08 01:21:21
问题 i have created custom fact ---> /etc/ansible/facts.d/hdfs.fact when i'm running the playbook with the following command - debug: var=ansible_local.hdfs run_once: true i'm getting as expected the following answer: PLAY [all] ********************************************************************* TASK [setup] ******************************************************************* ok: [cdh-2] ok: [cdh-3] ok: [cdh-1] TASK [preparation : debug] ***************************************************** ok:

Ansible - Set environment path as inventory variable

和自甴很熟 提交于 2021-01-28 12:20:02
问题 Osmc media player needs a specific path for playbooks https://github.com/osmc/osmc/issues/319 environment: PATH: "{{ ansible_env.PATH }}:/sbin:/usr/sbin" I was wondering whether I can set this as an environmental variable in the inventory for those machines, rather than have it in every playbook or create separate playbooks. In common usage - is that path likely to cause problems for general *nix machines if it is implemented on non-osmc installations? If you can't set this an an inventory

Write data with a PUT request with Ansible URI module

坚强是说给别人听的谎言 提交于 2021-01-28 04:53:41
问题 I'm just trying to translate this cURL call to ansible playbook. cURL call: curl -X PUT -d "value={aa}" "http://172.31.64.174:2379/v2/keys/coreos.com/network/config" Ansible playbook: - uri: url: "http://172.31.64.174:2379/v2/keys/coreos.com/network/config" method: PUT body: "value={aa}" I tried this one but server receive the PUT petition but value is not changed. This is the verbose output from the cURL procedure: * Trying 172.31.64.174... * Connected to 172.31.64.174 (172.31.64.174) port