ansible-playbook

Using a registered variable in ansible after removing single quotes

五迷三道 提交于 2019-12-20 06:03:54
问题 After registering the result of a task ,when i debug the variable. The value i get is in double quotes like "1234" . If i use in another module or ansible task it becomes [u'1234'] . I have removed character u and brackets using replace. How to get rid of single quotes which is ansible default. Actual output : '1234' expected output: 1234 Playbook snippet - uri: url: http://test/ws?Id=4a3d method: GET content_as_json: yes password: admin user: admin validate_certs: no return_content: yes

accessing inventory host variable in ansible playbook

廉价感情. 提交于 2019-12-20 03:01:04
问题 I am using ansible 2.1. I have the following inventory host file and a role being called by a play that needs access to the host file variable. Any thoughts on how to access it (currently getting an error): host file [test1] test-1 ansible_ssh_host=abc.def.ghi.jkl ansible_ssh_port=1212 [test2] test2-1 ansible_ssh_host=abc.def.ghi.mno ansible_ssh_port=1212 [test3] test3-1 ansible_ssh_host=abc.def.ghi.pqr ansible_ssh_port=1212 test3-2 ansible_ssh_host=abc.def.ghi.stu ansible_ssh_port=1212 [all

Case statement for setting var in Ansible/Jinja2

只谈情不闲聊 提交于 2019-12-18 12:18:58
问题 I'm using Ansible with Jinja2 templates, and this is a scenario that I can't find a solution for in Ansible's documentation or googling around for Jinja2 examples. Here's the logic that I want to achieve in Ansible: if {{ existing_ansible_var }} == "string1" new_ansible_var = "a" else if {{ existing_ansible_var }} == "string2" new_ansible_var = "b" <...> else new_ansible_var = "" I could probably do this by combining several techniques, the variable assignment from here: Set variable in jinja

Check if service exists with Ansible

与世无争的帅哥 提交于 2019-12-18 11:40:58
问题 I have an Ansible playbook for deploying a Java app as an init.d daemon. Being a beginner in both Ansible and Linux I'm having trouble to conditionally execute tasks on a host based on the host's status. Namely I have some hosts having the service already present and running where I want to stop it before doing anything else. And then there might be new hosts, which don't have the service yet. So I can't simply use service: name={{service_name}} state=stopped , because this will fail on new

how to define ssh private key for servers fetched by dynamic inventory in files

你离开我真会死。 提交于 2019-12-18 10:03:31
问题 I met one configuration problem when coding ansible playbook for ssh private key file. As we know, we can define combination with host server, ip & related ssh private key in ansible hosts file for static inventory servers. But i have no idea how to define that with dynamic inventory servers. Ex: --- - hosts: tag_Name_server1 gather_facts: no roles: - role1 - hosts: tag_Name_server2 gather_facts: no roles: - roles2 Below command is used to call that playbook: ansible-playbook test.yml -i ec2

How to upload encrypted file using ansible vault?

醉酒当歌 提交于 2019-12-17 23:33:26
问题 Does anyone have an example of decrypting and uploading a file using ansible-vault. I am thinking about keeping my ssl certificates encrypted in source control. It seems something like the following should work. --- - name: upload ssl crt copy: src=../../vault/encrypted.crt dest=/usr/local/etc/ssl/domain.crt 回答1: That's not going to work. What you will get is your encrypted.crt (with Ansible Vault) uploaded literally as domain.crt What you need to do is make your playbook part of a "Vault"

Quotes in ansible lineinfile

混江龙づ霸主 提交于 2019-12-17 19:33:50
问题 When I use lineinfile in ansible it is not writing ' , " characters lineinfile: 'dest=/home/xyz state=present line="CACHES="default""' it is giving CACHES=default but the desired output is CACHES="default" How to achieve this? 回答1: it appears you can escape the quotes: - lineinfile: dest=/tmp/xyz state=present line="CACHES=\"default\"" That gives this output: $ cat /tmp/xyz CACHES="default" You don't need to escape single quotes that are inside double quotes: - lineinfile: dest=/tmp/xyz state

Ansible remote_user vs ansible_user

孤人 提交于 2019-12-17 18:26:39
问题 The question is simple: what is the difference between ansible_user (former ansible_ssh_user ) and remote_user in Ansible, besides that the first one is set if configuration file and the latter one is set in plays / roles? How do they relate to -u / --user command line options? 回答1: They both seem to be the same. Take a look here: https://github.com/ansible/ansible/blob/c600ab81ee/lib/ansible/playbook/play_context.py#L46-L55 # the magic variable mapping dictionary below is used to translate #

Using a variable as a default value in vars_prompt in Ansible

久未见 提交于 2019-12-17 17:09:32
问题 I was trying to use vars_prompt in Ansible with default values taken from facts (or otherwise a previously defined variable). The playbook is intended be used as an ad-hoc one for initial provisioning. My playbook: --- - hosts: server01 gather_facts: True vars_prompt: - name: new_hostname prompt: please enter the name for the target default: "{{ ansible_hostname }}" private: no tasks: - debug: msg="{{ new_hostname }}" Current result: please enter the name for the target [{{ ansible_hostname }

How can escape colon in a string within an Ansible YAML file?

混江龙づ霸主 提交于 2019-12-17 10:57:13
问题 I want to change one line of my code in file /var/www/kibana/config.js during installation from elasticsearch: "http://"+window.location.hostname+":9200" to elasticsearch: "http://192.168.1.200:9200" Here I tried to use lineinfile to do that as show below - name: Comment out elasticsearch the config.js to ElasticSearch server lineinfile: dest=/var/www/kibana/config.js backrefs=true regexp="(elasticsearch.* \"http.*)$" line="elasticsearch\: \" {{ elasticsearch_URL }}:{{ elasticsearch_port }} \