ansible

Ansible variable in key/value key

谁说胖子不能爱 提交于 2021-02-20 13:44:32
问题 I'm passing env variables to a Docker container in an ansible playbook, how do I set an Ansible variable in the key in the key/value of an env? So this: - name: webproxy container docker_container: name: "webproxy" image: "webproxy" env: SERVICE_443_NAME: "webproxy" becomes this: - name: webproxy container docker_container: name: "webproxy" image: "webproxy" env: SERVICE_{{ port_number }}_NAME: "webproxy" 回答1: Use JSON notation to define a dictionary with environment variables: - name:

Write to csv file

我的未来我决定 提交于 2021-02-19 06:45:06
问题 I need some contents to be written in csv format to a file using ansible shell: ps -ef | grep java | awk '{print $1}' register: username shell: ps -ef | grep java | awk '{print $2}' register: id The output for username will be similar to : root admin test_admin The output for id will be similar to: 1232 4343 2233 so I want this to be written to a csv file as root,1232 admin,4343 test_admin,2233 Please suggest. 回答1: You can use a combination of the zip, map and join filters to achieve your

Reading multiple values from an env file with ansible and storing them as facts

时间秒杀一切 提交于 2021-02-19 05:30:07
问题 I have the following code which reads values from an environment (.env) file and stores them as facts: - name: Read values from environment shell: "source {{ env_path }}; echo $DB_PASSWORD" register: output args: executable: /bin/bash changed_when: false - name: Store read password set_fact: db_password: "{{ output.stdout }}" when: - db_password is undefined changed_when: false - name: Read values from environment shell: "source {{ env_path }}; echo $DB_USER" register: output args: executable

Reading multiple values from an env file with ansible and storing them as facts

不羁岁月 提交于 2021-02-19 05:29:26
问题 I have the following code which reads values from an environment (.env) file and stores them as facts: - name: Read values from environment shell: "source {{ env_path }}; echo $DB_PASSWORD" register: output args: executable: /bin/bash changed_when: false - name: Store read password set_fact: db_password: "{{ output.stdout }}" when: - db_password is undefined changed_when: false - name: Read values from environment shell: "source {{ env_path }}; echo $DB_USER" register: output args: executable

Need to hide failed log in ansible task

[亡魂溺海] 提交于 2021-02-18 10:43:30
问题 I am new to ansible tasks, am creating a yml which performs a login operation and if login gets failed, some script need to be called. - name: Logging Action shell: "/usr/local/bin/cqlsh -u xyzyx -p 1234abc" register: loginoutput ignore_errors: yes no_log: True - name: Run the cql script to create new user shell: sh create-new-user.cql" when: loginoutput|failed for the above one i created taks that works fine. My question, when performing login operation - it got failed and showing error

how to specify user name in host file of ansible

本小妞迷上赌 提交于 2021-02-18 10:03:45
问题 I am using the host file as below, [qa-workstations] 10.39.19.190 ansible_user=test ansible_ssh_pass=test I am using below command to execute "whoami" command in host root@Svr:~/ansible# ansible all -a "whoami" -i /etc/ansible/host 10.39.19.190 | success | rc=0 >> root ansible by default trying to use user name in which I have logged in, i.e root instead of test user which I have specified in host file It works fine when I try to pass the username in ansible cli command root@Svr:~/ansible#

Ansible SSH private key in source control?

旧时模样 提交于 2021-02-17 07:44:36
问题 I have been developing an Ansible playbook for a couple of weeks, therefore, my experience with such technology is relatively short. Part of my strategy includes using a custom ansible_ssh_user for provisioning hosts throughout the inventory, however, such user will need its own SSH key pair, which would involve some sort of a plan for holding/storing its correspondent private key. On a production environment, this playbook would be cloned/pulled and run inside a certain playbook node whose

ansible Jinja2 JSON loop last elements

梦想与她 提交于 2021-02-16 20:09:26
问题 Im trying to produce a JSON file from a Jinja2 template using variables passed from Ansible. As far as I know there are no modules that help me here (stand to be corrected?). Im stuck on the last loop { "items": [ {% for host in hostvars %} {"apiversion": "v1", "lastrunupdate": "{{ hostvars[host]['date'] }}", "hostname": "null", "hostip": "{{ hostvars[host]['inventory_hostname'] }}", "whoami": "{{ hostvars[host]['whoamiraw'] }}", "serialnumber": "{{ hostvars[host]['serial'] }}", "version": "{

Ansible variable name `environment` is reserved?

情到浓时终转凉″ 提交于 2021-02-16 16:13:33
问题 I've got a strange situation today. I called one of my variables in a playbook environment . If I dump variables using debug instruction, it is shown ok "environment": "development", But if I try to access it from a script using {{ environment }} it is always assigned a value of {} . I renamed it and it worked ok. Why is that? Is environment a reserved name in Ansible? I checked variable dump - there is no clashes with defined vars. 回答1: I found a statement regarding environment in the Google

Ansible variable name `environment` is reserved?

岁酱吖の 提交于 2021-02-16 16:11:05
问题 I've got a strange situation today. I called one of my variables in a playbook environment . If I dump variables using debug instruction, it is shown ok "environment": "development", But if I try to access it from a script using {{ environment }} it is always assigned a value of {} . I renamed it and it worked ok. Why is that? Is environment a reserved name in Ansible? I checked variable dump - there is no clashes with defined vars. 回答1: I found a statement regarding environment in the Google