ansible

Unable to run script despite escalating privilege in Ansible

天大地大妈咪最大 提交于 2019-12-25 00:12:37
问题 Im trying to run a shell script on the host machine after copying it over there using ansible. The script has 777 permissions. Please read the below question as it gives the full scope of the actual issue that we are trying to deal with Set different ORACLE_HOME and PATH environment variable using Ansible - name: Run the Script [List] shell: "/tmp/sqlscript/sql_select.sh {{item}} >> /tmp/sqlscript/output.out" become: yes become_method: sudo become_user: oracle register: orh with_items: "{{

Improving use of add_host in ansible [duplicate]

孤街醉人 提交于 2019-12-24 23:15:43
问题 This question already has answers here : Ansible - Write multiple line output to file (2 answers) local_action: shell error concatenate files (1 answer) Closed last year . I want to put hosts based on info I found on it in a in-memory group that I'll use on a later play. I use this way based on writing the hostname of the target on the control node and then using this list to loop over with add_host , as add_host " bypasses the host loop and only runs once for all the hosts in the play " (I

Ansible: Loop over a list of services and disable those from a list of unwanted services which are actually present

别说谁变了你拦得住时间么 提交于 2019-12-24 22:43:41
问题 I'm using Ansible to build a base image from a base installation of RHEL7.5 One of the things I want to do is to disable unwanted services. So I do this: - name: "| disable unwanted services" service: name: "{{ item }}" enabled: no state: stopped loop: "{{ disabled_services }}" when: disabled_services is defined Which works fine, testing on localhost; then I try it on a test build, and it errors because one of the services I'm trying to manage isn't even present. Say for example that disabled

Formatting set_fact variable

微笑、不失礼 提交于 2019-12-24 22:22:21
问题 I need to have all the userid in a single variable, all separated by \n. Code is as below. - name: Retrieve the user id and instance shell: ls -l {{item}} | grep -v total| awk '{print $3}' register: find_result_userid with_items: - /tmp/log/logs/log1 - /tmp/log/logs/log2 - /tmp/log/logs/log3 - name: Combine all userid set_fact: server_names: "{{ find_result_userid.results | map(attribute='stdout_lines')|list }}" The output is as below. ok: [localhost] => { "ansible_facts": { "server_names": [

Ansible check if inventory_hostname is in list

拥有回忆 提交于 2019-12-24 22:08:39
问题 I am trying to check if inventory_hostname is in a list into an imported variable. vars/users.yml file: --- users: - username: user1 comment: "User 1" group: admin password: "sha password" keys: active: - "ssh-rsa etc" admin: yes - username: user2 comment: "User 2" group: users groups: deployer keys: active: - "ssh-rsa etc" hosts: user: - host1 - host2 deployer: - host3 I want to execute a task only if inventory_hostname is into any of hosts lists (user, deployer, others ...). I tried this: -

Print out only failed tasks - Ansible

放肆的年华 提交于 2019-12-24 18:46:08
问题 I have created an Ansible playbook which just checks the connection to target hosts on a specific port. Here is my playbook - name: ACL check to target machines. hosts: all gather_facts: False vars: target_hosts: - server1 18089 - server1 8089 - server1 18000 tasks: - name: execute the command command: "nc -vz {{ item }}" with_items: "{{ target_hosts }}" The output i get when i execute the playbook contains both changed(success) and failed. In real scenario i have many number of target hosts,

Creating a comma separated string from a dictionary in Ansible

佐手、 提交于 2019-12-24 18:23:44
问题 I want to write an Ansible role to be able to alter a given Kafka topic. I am using a dictionary of key/value pairs. The command module is then used to execute a Kafka script that take a string of comma separated values. For instance, use app_kafka_topic list: --- app_kafka_topic: cleanup.policy : - "delete" retention.ms : - "146800000" partitions : - "6" replication-factor : - "2" and create the string : "cleanup.policy=delete,retention.ms=146800000,partitions=6,replication-factor=2" This is

tidb运维优化

拟墨画扇 提交于 2019-12-24 18:07:01
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> tidb默认变量 SHOW GLOBAL VARIABLES like '%mem_quota%' # 查看内存使用阈值 set @@tidb_mem_quota_query = 8 << 30; -- 配置整条SQL的内存使用阈值为8GB SELECT @@tidb_mem_quota_query -- 查看当前变量 慢sql show variables like 'tidb_slow_query_file'; # 查看慢sql文件位置 admin show slow recent 10; # 查看最近10条慢sql admin show slow top 3; -- 最慢的查询记录 admin show slow top all 5; -- 包含内部SQL的慢查询记录 select query_time, query from information_schema.slow_query where is_internal = false -- 排除 TiDB 内部的慢查询 SQL order by query_time desc limit 5; # 搜索排名前5的慢SQL select query_time, query, user from information_schema.slow_query

Enable Apache site using Ansible

▼魔方 西西 提交于 2019-12-24 17:15:31
问题 I am running a playbook from a python script. I am following this code The following command works perfectly. ansible -i path/to/inventory.yml host_name -m command -a"a2ensite site_name" But when I try to do the same by executing a playbook from the python script. It says the site doesn't exist. Following is the playbook. playbook = dict( name = "Enable Site", hosts = ['token_server'], gather_facts = 'no', tasks = [ dict(action=dict(module='command', args="a2ensite " + site_name), register=

Elegant way to handle from_json filter failure with default value

这一生的挚爱 提交于 2019-12-24 15:45:13
问题 I'm seeking for your ideas to elegantly handle a from_json filter failure when it happens. I have a generic task in an ansible role that I use to call different groovy script in sonatype nexus repository manager (the full role is available on github) - name: Calling Groovy script {{ script_name }} uri: url: "{{ nexus_api_scheme }}://{{ nexus_api_hostname }}:{{ nexus_api_port }}\ {{ nexus_api_context_path }}{{ nexus_rest_api_endpoint }}/{{ script_name }}/run" user: 'admin' password: "{{